bonsaif-ui 0.1.126 → 0.1.129

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.
@@ -1,10 +1,10 @@
1
- (function(Y,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("react"),require("react/jsx-runtime"),require("react-icons/hi2"),require("react-dom"),require("recharts"),require("overlayscrollbars"),require("sonner"),require("overlayscrollbars-react"),require("react-day-picker"),require("react-day-picker/dist/style.css"),require("react-icons/fi")):typeof define=="function"&&define.amd?define(["exports","react","react/jsx-runtime","react-icons/hi2","react-dom","recharts","overlayscrollbars","sonner","overlayscrollbars-react","react-day-picker","react-day-picker/dist/style.css","react-icons/fi"],o):(Y=typeof globalThis<"u"?globalThis:Y||self,o(Y.BonsaifUI={},Y.React,Y.jsxRuntime,Y.ReactIconsHi2,Y.ReactDOM,Y.Recharts,Y.OverlayScrollbarsGlobal,Y.Sonner,Y.OverlayScrollbarsReact,Y.ReactDayPicker,Y.ReactDayPickerStyles,Y.ReactIconsFi))})(this,(function(Y,o,t,q,dt,Ce,ka,Ho,Bo,Sa,rm,Ci){"use strict";"use client";function jt(...e){return e.filter(Boolean).join(" ")}function Ei({variant:e="primary",className:r,type:n="button",children:a,...s}){return t.jsx("button",{className:jt("bonsaif-ui-button",`bonsaif-ui-button--${e}`,r),type:n,...s,children:a})}function Fo({value:e,onChange:r,placeholder:n,className:a="",autoFocus:s=!1,forceExpanded:l=!1,onEscape:i,size:c="default",inputTabIndex:d}){const u=o.useRef(null),[m,b]=o.useState(!1),f=l||m||e.trim().length>0,g=c==="sm"?"h-9 rounded-md":"h-10 rounded-lg",v=a||"w-48 max-w-full sm:w-64 lg:w-72";o.useEffect(()=>{var h;s&&((h=u.current)==null||h.focus())},[s]);const k=()=>{var h;b(!0),(h=u.current)==null||h.focus()};return t.jsxs("div",{className:`relative min-w-0 max-w-full flex-shrink-0 overflow-visible transition-[width] duration-200 ease-out ${f?v:"w-24 sm:w-28"}`,onMouseDown:h=>{f||(h.preventDefault(),k())},children:[t.jsx(q.HiMagnifyingGlass,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 pointer-events-none transition-colors duration-200",style:{color:"var(--text-muted)",left:"var(--page-header-control-icon-left, 12px)"}}),t.jsx("input",{ref:u,type:"text",tabIndex:d,"aria-label":n,value:e,onChange:h=>r(h.target.value),onKeyDown:h=>{h.key==="Escape"&&(i==null||i())},placeholder:f?n:"Buscar",className:`${g} w-full py-0 text-sm leading-none placeholder:text-[var(--text-muted)] focus:outline-none transition-all duration-200 ${f?"pl-9 pr-8":"cursor-pointer pl-9 pr-3"}`,style:{height:`var(--page-header-control-height, ${c==="sm"?"36px":"40px"})`,paddingLeft:"calc(var(--page-header-control-icon-left, 12px) + 24px)",paddingRight:f?"calc(var(--page-header-control-padding-x, 14px) + 18px)":"var(--page-header-control-padding-x, 14px)",background:"color-mix(in srgb, var(--bg-card) 86%, transparent)",border:"1px solid var(--border)",color:"var(--text-main)"},onFocus:h=>{b(!0),h.currentTarget.style.borderColor="var(--primary)",h.currentTarget.style.boxShadow="0 0 0 3px rgba(59,130,246,0.12)"},onBlur:h=>{b(!1),h.currentTarget.style.borderColor="var(--border)",h.currentTarget.style.boxShadow="none"}}),e&&t.jsx("button",{type:"button",onClick:()=>r(""),className:"absolute right-2 top-1/2 flex !h-6 !w-6 -translate-y-1/2 items-center justify-center rounded-full !p-0 leading-none transition-colors hover:bg-black/5",style:{color:"var(--text-muted)",right:"var(--page-header-control-padding-x, 8px)"},"aria-label":"Limpiar búsqueda",children:t.jsx(q.HiXMark,{className:"h-3.5 w-3.5 flex-shrink-0"})})]})}const Po=o.createContext({});let _o=0;const zo="bonsaif-ui:hide-tooltips";function pn(e=700){_o=Date.now()+e}function Mi(){return Date.now()>_o}function hn(e){if(typeof document>"u")return!1;const r=Array.from(document.querySelectorAll('[data-bonsaif-overlay="true"], [role="menu"], [role="dialog"][aria-modal="true"], [aria-hidden="false"] [aria-modal="true"]'));return e&&r.some(n=>n.contains(e))?!1:r.length>0}function Ti(e){var a;const r=Array.from(e.querySelectorAll("*")).filter(s=>{var l;return s.scrollWidth>s.clientWidth&&!!((l=s.textContent)!=null&&l.trim())&&s.tagName.toLowerCase()!=="svg"&&!s.closest("svg")});return(e.scrollWidth>e.clientWidth||r.length>0)&&(((a=r[0])==null?void 0:a.textContent)??e.textContent??"").trim()||null}function nr({children:e,content:r,onlyWhenOverflow:n=!1,interactive:a=!1,followCursor:s=!0,placement:l="bottom",showArrow:i=!1,className:c="",tooltipClassName:d="",style:u,tooltipStyle:m,as:b="div"}){const f=o.useRef(null),g=o.useRef(null),v=o.useRef(null),k=o.useRef(!1),[h,C]=o.useState(null),[M,y]=o.useState("");o.useEffect(()=>{const L=f.current;L&&(L.querySelectorAll("[title]").forEach(Q=>{const z=Q.getAttribute("title");z&&(Q.getAttribute("aria-label")||Q.setAttribute("aria-label",z),Q.removeAttribute("title"))}),L.querySelectorAll("svg title").forEach(Q=>Q.remove()))}),o.useLayoutEffect(()=>{if(!h)return;const L=g.current;if(!L)return;const Q=12,z=14,se=L.getBoundingClientRect(),re=window.innerWidth-se.width-Q,R=window.innerHeight-se.height-Q;let V=h.mouseX+z,B=h.mouseY+z,le,j;if(!s&&f.current){const W=f.current.getBoundingClientRect(),ae=W.left+W.width/2,H=W.top+W.height/2;l==="top"?(V=ae-se.width/2,B=W.top-se.height-z,j=se.height-1):l==="left"?(V=W.left-se.width-z,B=H-se.height/2,le=se.width-1):l==="right"?(V=W.right+z,B=H-se.height/2,le=-7):(V=ae-se.width/2,B=W.bottom+z,j=-7)}if(s&&(V>re&&(V=h.mouseX-se.width-z),B>R&&(B=h.mouseY-se.height-z)),V=Math.min(Math.max(Q,V),Math.max(Q,re)),B=Math.min(Math.max(Q,B),Math.max(Q,R)),!s&&f.current){const W=f.current.getBoundingClientRect(),ae=W.left+W.width/2,H=W.top+W.height/2;l==="top"||l==="bottom"?le=Math.min(Math.max(14,ae-V),se.width-14):j=Math.min(Math.max(14,H-B),se.height-14)}(Math.abs(V-h.x)>.5||Math.abs(B-h.y)>.5||le!==h.arrowX||j!==h.arrowY)&&C(W=>W&&{...W,x:V,y:B,arrowX:le,arrowY:j})},[s,l,h]);const x=()=>{v.current&&(window.clearTimeout(v.current),v.current=null)},w=(L,Q)=>{if(!Mi()||k.current)return;const z=f.current;if(z&&!hn(z)){if(n){const se=Ti(z);if(!se)return;y(se)}!n&&!r||C({mouseX:L,mouseY:Q,x:L+14,y:Q+14})}},N=()=>{const L=f.current;if(!L)return;const Q=L.getBoundingClientRect();w(Q.left+Q.width/2,Q.bottom)},A=()=>{x(),C(null)},T=()=>{if(!a){A();return}x(),v.current=window.setTimeout(()=>C(null),120)},U=()=>{pn(),k.current=!0,A()},K=()=>{k.current=!1};o.useEffect(()=>{if(!h)return;if(hn(f.current)){C(null);return}const L=()=>C(null),Q=()=>{pn(),k.current=!0,C(null)};document.addEventListener("pointerdown",Q,!0),document.addEventListener("click",Q,!0),document.addEventListener("scroll",L,!0),window.addEventListener("blur",L),document.addEventListener("visibilitychange",L),document.addEventListener("keydown",L,!0);const z=new MutationObserver(()=>{hn(f.current)&&C(null)});return z.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["role","aria-modal","aria-hidden","class"]}),()=>{document.removeEventListener("pointerdown",Q,!0),document.removeEventListener("click",Q,!0),document.removeEventListener("scroll",L,!0),window.removeEventListener("blur",L),document.removeEventListener("visibilitychange",L),document.removeEventListener("keydown",L,!0),z.disconnect()}},[h]),o.useEffect(()=>{const L=()=>pn(),Q=()=>{pn(),k.current=!0,C(null)};return document.addEventListener("pointerdown",L,!0),document.addEventListener("click",L,!0),document.addEventListener("keydown",L,!0),window.addEventListener(zo,Q),()=>{document.removeEventListener("pointerdown",L,!0),document.removeEventListener("click",L,!0),document.removeEventListener("keydown",L,!0),window.removeEventListener(zo,Q)}},[]);const Z=n?M:r;return t.jsxs(t.Fragment,{children:[t.jsx(b,{ref:L=>{f.current=L},className:c,style:u,onMouseEnter:L=>{x(),K(),s?w(L.clientX,L.clientY):N()},onMouseMove:L=>{h&&s&&w(L.clientX,L.clientY)},onMouseDown:U,onClick:U,onMouseLeave:()=>{K(),T()},onFocus:N,onBlur:A,children:e}),h&&Z&&!hn(f.current)?dt.createPortal(t.jsxs("div",{ref:g,role:"tooltip",className:d,onMouseEnter:a?x:void 0,onMouseLeave:a?T:void 0,style:{position:"fixed",top:h.y,left:h.x,zIndex:9999,background:"var(--bg-card)",border:"1px solid var(--border)",borderRadius:6,padding:"5px 10px",fontSize:12,color:"var(--text-main)",boxShadow:"0 4px 16px rgba(0,0,0,0.35)",pointerEvents:a?"auto":"none",maxWidth:"min(420px, calc(100vw - 24px))",whiteSpace:"normal",lineHeight:1.6,overflowWrap:"anywhere",...m},children:[i&&t.jsx("span",{"aria-hidden":"true",style:{position:"absolute",width:12,height:12,background:(m==null?void 0:m.background)??"var(--bg-card)",borderLeft:l==="right"?(m==null?void 0:m.border)??"1px solid var(--border)":void 0,borderTop:l==="bottom"||l==="right"?(m==null?void 0:m.border)??"1px solid var(--border)":void 0,borderRight:l==="left"?(m==null?void 0:m.border)??"1px solid var(--border)":void 0,borderBottom:l==="top"||l==="left"?(m==null?void 0:m.border)??"1px solid var(--border)":void 0,transform:"rotate(45deg)",left:h.arrowX===void 0?void 0:h.arrowX-6,top:h.arrowY===void 0?void 0:h.arrowY-6,zIndex:-1}}),Z]}),document.body):null]})}function Wo(e){if(e!==void 0)return typeof e=="number"?`${e}px`:e}const $i="inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap leading-none font-medium transition-all duration-150 focus:outline-none disabled:opacity-50 rounded-lg",Ai={primary:"border border-[var(--border)] text-[var(--text-main)] hover:border-[var(--border)] hover:bg-[var(--bg-input)] active:scale-[0.98] transition-colors",secondary:"border border-[var(--border)] text-[var(--text-main)] hover:border-[var(--border)] hover:bg-[var(--bg-input)] active:scale-[0.98] transition-colors",danger:"border border-[var(--border)] text-[var(--danger)] hover:border-[var(--danger)] hover:bg-[var(--danger-bg)] active:scale-[0.98] transition-colors",ghost:"text-[var(--text-secondary)] hover:opacity-70",icon:"text-[var(--text-muted)] hover:text-[var(--primary)] hover:bg-primary/5"},Li="border border-[var(--border)] text-[var(--text-muted)] shadow-sm shadow-black/5 hover:border-[var(--border)] hover:bg-[var(--bg-input)] hover:text-[var(--primary)] active:scale-[0.98] transition-colors",Di={xs:"h-8 px-2.5 text-xs",sm:"h-9 px-3.5 text-xs",md:"h-10 px-3.5 text-sm",lg:"h-11 px-4 text-sm font-semibold"},Ii={xs:"h-8 w-8",sm:"h-9 w-9",md:"h-10 w-10",lg:"h-10 w-10"},Oi={primary:{background:"var(--bg-card)"},secondary:{background:"var(--bg-card)"},danger:{background:"var(--bg-card)"},ghost:{},icon:{}};function Ca(e){return typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(Ca).join(" ").trim():o.isValidElement(e)?Ca(e.props.children):""}function Hi(e){return o.Children.toArray(e).find(o.isValidElement)??null}function Ue({variant:e="primary",size:r="md",loading:n=!1,icon:a,tooltip:s,iconOnly:l,height:i,padding:c,children:d,className:u="",disabled:m,style:b,...f}){const g=o.useContext(Po),v=l??g.iconOnly??e==="icon",k=g.compact??!1,h=g.headerAction??!1,C=h&&r==="md"?"sm":k&&!h&&r==="md"?"xs":r,M=e==="icon"||v,y=h&&M,x=Ca(d),w=s??f.title??f["aria-label"]??(v?x:void 0),N=w?void 0:f.title,A=f["aria-label"]??(typeof w=="string"?w:x||void 0),T=n?null:a??(v?Hi(d):null),U=t.jsxs("button",{...f,title:N,"aria-label":A,"data-variant":e,"data-size":C,"data-icon":M?"true":void 0,disabled:m||n,className:`${$i} ${y?Li:Ai[e]} ${M?Ii[C]:Di[C]} ${k&&!M?"px-2.5":""} ${u}`,style:{...Oi[e],height:Wo(i),padding:Wo(c),...b,...h&&!M?{height:"var(--page-header-control-height, 34px)",padding:"0 var(--page-header-control-padding-x, 10px)",borderRadius:"8px"}:null,...y?{width:"var(--page-header-control-height, 40px)",height:"var(--page-header-control-height, 40px)",padding:0,background:"var(--bg-card)",borderRadius:"8px"}:null},children:[n?t.jsx("span",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):T,!v&&d]});return w?t.jsx(nr,{as:"span",content:w,className:"inline-flex shrink-0",children:U}):U}const ut={background:"color-mix(in srgb, var(--text-muted) 26%, var(--bg-input))"};function gn({rows:e=8,columns:r=7,showToolbar:n=!0,showPagination:a=!0,compact:s=!1,className:l=""}){const i=Math.max(3,Math.min(r,12)),c=Math.max(3,Math.min(e,20)),d=s?"px-2 py-2":"px-3 py-2.5",u=s?"px-2 py-2":"px-3 py-3";return t.jsxs("div",{className:`w-full min-w-0 overflow-hidden rounded-lg border border-[var(--border)] bg-[var(--bg-card)] ${l}`,"aria-busy":"true","aria-label":"Cargando tabla",children:[n&&t.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-[var(--border)] px-3 py-2",children:[t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[t.jsx("div",{className:"h-7 w-14 shrink-0 animate-pulse rounded-md",style:ut}),t.jsx("div",{className:"h-7 max-w-md flex-1 animate-pulse rounded-md",style:ut})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[t.jsx("div",{className:"h-7 w-7 animate-pulse rounded-md",style:ut}),t.jsx("div",{className:"h-7 w-7 animate-pulse rounded-md",style:ut})]})]}),t.jsx("div",{className:"overflow-x-auto",children:t.jsxs("div",{className:"min-w-full",style:{display:"grid",gridTemplateColumns:`repeat(${i}, minmax(96px, 1fr))`},children:[Array.from({length:i}).map((m,b)=>t.jsx("div",{className:`${u} border-b border-[var(--border)]`,style:{background:"color-mix(in srgb, var(--bg-input) 55%, transparent)"},children:t.jsx("div",{className:"h-3 animate-pulse rounded-md",style:{...ut,width:`${48+b*17%40}%`}})},`h-${b}`)),Array.from({length:c}).map((m,b)=>Array.from({length:i}).map((f,g)=>t.jsx("div",{className:`${d} ${b<c-1?"border-b border-[var(--border)]":""}`,children:t.jsx("div",{className:"h-3.5 animate-pulse rounded-md",style:{...ut,width:`${46+(b*13+g*11)%42}%`,minWidth:28}})},`c-${b}-${g}`)))]})}),a&&t.jsxs("div",{className:"flex items-center justify-between gap-3 border-t border-[var(--border)] px-3 py-2",style:{background:"color-mix(in srgb, var(--bg-input) 40%, transparent)"},children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"h-3 w-28 animate-pulse rounded-md",style:ut}),t.jsx("div",{className:"h-7 w-14 animate-pulse rounded-md",style:ut})]}),t.jsx("div",{className:"flex items-center gap-1",children:Array.from({length:4}).map((m,b)=>t.jsx("div",{className:"h-7 w-7 animate-pulse rounded-md",style:ut},b))}),t.jsx("div",{className:"h-3 w-16 animate-pulse rounded-md",style:ut})]})]})}function Bi({size:e="md"}){const r=e==="sm"?"h-7 w-7":"h-9 w-9";return t.jsx("div",{className:`${r} animate-spin rounded-full border-2 border-[var(--border)] border-t-[var(--primary)]`,"aria-hidden":!0})}function Fi({logoSrc:e,logoAlt:r}){return e?t.jsxs("span",{className:"relative flex h-16 w-16 items-center justify-center","aria-hidden":!1,children:[t.jsx("span",{className:"absolute inset-0 rounded-2xl opacity-40 blur-xl",style:{background:"radial-gradient(circle, color-mix(in srgb, var(--primary) 45%, transparent) 0%, transparent 70%)"}}),t.jsx("img",{src:e,alt:r,className:"relative h-14 w-14 rounded-2xl object-contain shadow-sm shadow-black/10"})]}):null}function jo({variant:e="page",title:r="Cargando...",description:n,logoSrc:a,logoAlt:s,appearance:l="card",rows:i=6,columns:c=7,children:d,className:u=""}){if(e==="table")return t.jsx(gn,{rows:i,columns:c,className:u});if(e==="sections")return t.jsx(Pi,{rows:i});if(e==="cards")return t.jsx(_i,{rows:i});const m=s||(typeof r=="string"?r:"Aplicación"),b=l==="bare",f=t.jsxs("div",{className:`flex flex-col items-center text-center ${b?"gap-5":"gap-3"}`,children:[a?t.jsx(Fi,{logoSrc:a,logoAlt:m}):null,t.jsx(Bi,{size:b?"md":"sm"}),t.jsxs("div",{className:b?"space-y-1.5":"",children:[t.jsx("p",{className:b?"text-base font-semibold tracking-tight text-[var(--text-main)]":"text-sm font-semibold text-[var(--text-main)]",children:r}),n?t.jsx("p",{className:b?"text-sm font-medium text-[var(--text-muted)]":"mt-1 text-xs text-[var(--text-muted)]",children:n}):null,d&&t.jsx("div",{className:"mt-1 text-xs text-[var(--text-muted)]",children:d})]})]});return b?t.jsx("div",{className:`flex min-h-[240px] w-full items-center justify-center p-8 ${u}`,role:"status","aria-live":"polite","aria-busy":"true",children:f}):t.jsx("div",{className:`flex min-h-[240px] items-center justify-center rounded-lg border border-[var(--border)] bg-[var(--bg-card)] p-6 ${u}`,role:"status","aria-live":"polite","aria-busy":"true",children:f})}function Pi({rows:e}){return t.jsx(gn,{rows:e,columns:7})}function _i({rows:e}){return t.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:Array.from({length:e}).map((r,n)=>t.jsxs("div",{className:"rounded-lg border border-[var(--border)] bg-[var(--bg-card)] p-4",children:[t.jsx("div",{className:"h-4 w-2/3 animate-pulse rounded-md",style:ut}),t.jsx("div",{className:"mt-3 h-3 w-full animate-pulse rounded-md",style:ut}),t.jsx("div",{className:"mt-2 h-3 w-4/5 animate-pulse rounded-md",style:ut})]},n))})}function qo(e){const r=e.split("/").filter(Boolean);return(r[r.length-1]??e).replace(/^lv_/,"").split(/[-_]/).filter(Boolean).map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(" ")}function Uo(e){return e.normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().trim()}function zi(e){return[e.label,qo(e.service),e.description,e.service].filter(Boolean).join(" ")}function Wi(e){return typeof e=="function"?e:e.default}function ji(e,r){return t.jsx("div",{className:"flex min-h-[220px] items-center justify-center rounded-lg border border-[var(--border)] bg-[var(--bg-card)] p-6 text-center",children:t.jsxs("div",{className:"max-w-md",children:[t.jsx("p",{className:"text-sm font-semibold text-[var(--text-main)]",children:"No se pudo cargar este modulo"}),t.jsx("p",{className:"mt-1 text-xs text-[var(--text-muted)]",children:e.message}),t.jsx(Ue,{className:"mt-4",height:36,padding:"0 14px",onClick:r,children:"Reintentar"})]})})}function qi({parentPanel:e,parentPanelComponent:r,renderParentPanel:n,parent:a,context:s,links:l,moduleRegistry:i,loadModule:c,activeService:d,initialService:u,onActiveServiceChange:m,canAccess:b,keepAlive:f=!0,title:g,subtitle:v,emptyState:k,loadingState:h,errorState:C=ji,renderTabLabel:M,searchableTabs:y="auto",tabsSearchThreshold:x=6,tabsSearchPlaceholder:w="Buscar modulo...",tabsSearchValue:N,onTabsSearchChange:A,emptySearchState:T,showTabCount:U=!0,className:K="",parentClassName:Z="",contentClassName:L="",tabsClassName:Q=""}){var lt;const z=o.useMemo(()=>l.filter(me=>!me.hidden&&((b==null?void 0:b(me,s))??!0)),[b,s,l]),se=(lt=z.find(me=>!me.disabled))==null?void 0:lt.service,[re,R]=o.useState(u??se??""),[V,B]=o.useState({}),[le,j]=o.useState({}),[W,ae]=o.useState(""),[H,D]=o.useState(!1),$=o.useRef(le),oe=o.useRef(0),G=N??W,X=Uo(G),S=y===!0||y==="auto"&&z.length>=x,O=S&&G.trim().length>0,I=o.useMemo(()=>X?z.filter(me=>Uo(zi(me)).includes(X)):z,[X,z]),te=d??re,P=z.find(me=>me.service===te)??z.find(me=>!me.disabled);o.useEffect(()=>{!P&&se&&R(se)},[se,P]),o.useEffect(()=>{$.current=le},[le]);const ce=me=>{me.disabled||(d||R(me.service),m==null||m(me.service,me))},he=me=>{N===void 0&&ae(me),A==null||A(me)},ie=(me,Ye)=>{const qe=I.filter(ze=>!ze.disabled),ct=qe.findIndex(ze=>ze.service===Ye.service);ct<0||((me.key==="ArrowRight"||me.key==="ArrowDown")&&(me.preventDefault(),ce(qe[(ct+1)%qe.length])),(me.key==="ArrowLeft"||me.key==="ArrowUp")&&(me.preventDefault(),ce(qe[(ct-1+qe.length)%qe.length])),me.key==="Home"&&(me.preventDefault(),ce(qe[0])),me.key==="End"&&(me.preventDefault(),ce(qe[qe.length-1])))},ge=o.useCallback(()=>{if(!P)return;const me=P.service,Ye=$.current[me];if(Ye!=null&&Ye.loading||Ye!=null&&Ye.component&&f)return;const qe=(i==null?void 0:i[me])??c;if(!qe){j(ze=>({...ze,[me]:{loading:!1,error:new Error(`No module loader found for service "${me}".`)}}));return}const ct=++oe.current;j(ze=>({...ze,[me]:{...ze[me],loading:!0,error:void 0}})),qe(P,s).then(ze=>{if(ct!==oe.current&&!f)return;const bt=Wi(ze);j(mt=>({...mt,[me]:{component:bt,loading:!1}}))}).catch(ze=>{const bt=ze instanceof Error?ze:new Error(String(ze));j(mt=>({...mt,[me]:{...mt[me],loading:!1,error:bt}}))})},[s,f,c,i,P]);o.useEffect(ge,[ge]);const Te=P?V[P.service]??null:null,Le=P?le[P.service]:void 0,It=Le==null?void 0:Le.component,ft=me=>{P&&B(Ye=>({...Ye,[P.service]:me}))},Qe=()=>{P&&B(me=>({...me,[P.service]:null}))},Ot={context:s,parent:a,links:l,visibleLinks:z,filteredLinks:I,selectedLink:P,selectedService:P==null?void 0:P.service,activeItemId:Te,tabsSearch:G,onSelectService:ce,onOpenDetail:ft,onBackToList:Qe},Se=n?n(Ot):r?t.jsx(r,{...Ot}):e;return t.jsxs("section",{className:`grid min-h-[520px] gap-4 lg:grid-cols-[minmax(260px,360px)_minmax(0,1fr)] ${K}`,children:[t.jsx("aside",{className:`min-w-0 rounded-lg border border-[var(--border)] bg-[var(--bg-card)] p-4 ${Z}`,children:Se}),t.jsxs("div",{className:`relative min-w-0 overflow-visible rounded-lg border border-[var(--border)] bg-[var(--bg-card)] ${L}`,children:[(g||v||S||U)&&t.jsx("div",{className:"relative border-b border-[var(--border)] px-4 py-3",children:t.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[g&&t.jsx("h2",{className:"truncate text-sm font-semibold text-[var(--text-main)]",children:g}),v&&t.jsx("p",{className:"mt-1 line-clamp-2 text-xs text-[var(--text-muted)]",children:v})]}),(S||U)&&t.jsxs("div",{className:"flex min-w-0 flex-shrink-0 items-center justify-end gap-2",children:[U&&t.jsxs("span",{className:"hidden text-xs font-semibold text-[var(--text-muted)] transition-opacity duration-200 sm:inline",children:[I.length," / ",z.length]}),S&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:`origin-right overflow-hidden transition-[width,opacity,transform] duration-200 ease-out ${H?"w-[min(20rem,44vw)] translate-x-0 opacity-100":"w-0 translate-x-2 opacity-0"}`,"aria-hidden":!H,children:t.jsx(Fo,{value:G,onChange:he,placeholder:w,className:"w-full",autoFocus:H,forceExpanded:!0,onEscape:()=>D(!1),size:"sm",inputTabIndex:H?0:-1})}),t.jsx("button",{type:"button","aria-label":H?"Cerrar busqueda":"Buscar tabs","aria-expanded":H,onClick:()=>{H&&G&&he(""),D(me=>!me)},className:`inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border transition-all duration-200 hover:scale-[1.03] active:scale-95 ${H||O?"border-[var(--primary)] bg-[var(--bg-input)] text-[var(--text-main)] shadow-sm":"border-[var(--border)] text-[var(--text-muted)] hover:bg-[var(--bg-input)] hover:text-[var(--text-main)]"}`,children:t.jsx("span",{className:"grid h-4 w-4 place-items-center transition-transform duration-200",children:H||O?t.jsx(q.HiXMark,{className:"h-4 w-4"}):t.jsx(q.HiMagnifyingGlass,{className:"h-4 w-4"})})})]})]})]})}),t.jsx("div",{role:"tablist","aria-label":g??"Modulos relacionados",className:`flex gap-1 overflow-x-auto border-b border-[var(--border)] bg-[var(--bg-input)] px-2 py-1.5 transition-colors duration-200 ${Q}`,children:I.length>0?I.map(me=>{const Ye=me.service===(P==null?void 0:P.service);return t.jsx("button",{type:"button",role:"tab","aria-selected":Ye,disabled:me.disabled,onClick:()=>ce(me),onKeyDown:qe=>ie(qe,me),className:`inline-flex h-9 min-w-max items-center gap-2 rounded-md border px-3 text-xs font-semibold transition-all duration-200 disabled:cursor-not-allowed disabled:opacity-50 ${Ye?"border-[var(--primary)] bg-[var(--bg-card)] text-[var(--text-main)] shadow-sm":"border-transparent text-[var(--text-muted)] hover:bg-[var(--bg-card)] hover:text-[var(--text-main)]"}`,children:M?M(me,Ye):t.jsxs(t.Fragment,{children:[me.icon,t.jsx("span",{children:me.label??qo(me.service)}),me.badge&&t.jsx("span",{className:"rounded-full bg-[var(--bg-input)] px-1.5 py-0.5 text-[10px] text-[var(--text-muted)]",children:me.badge})]})},me.service)}):t.jsx("div",{className:"flex min-h-9 flex-1 items-center rounded-md border border-dashed border-[var(--border)] px-3 text-xs text-[var(--text-muted)]",children:T??"No hay modulos que coincidan con la busqueda."})}),(P==null?void 0:P.description)&&t.jsx("div",{className:"border-b border-[var(--border)] px-4 py-2 text-xs text-[var(--text-muted)]",children:P.description}),t.jsxs("div",{className:"min-h-[420px] p-4",children:[!P&&(k??t.jsx("div",{className:"flex min-h-[220px] items-center justify-center rounded-lg border border-dashed border-[var(--border)] text-sm text-[var(--text-muted)]",children:"No hay modulos disponibles."})),P&&(Le==null?void 0:Le.loading)&&(h??t.jsx(jo,{title:"Cargando modulo..."})),P&&(Le==null?void 0:Le.error)&&C(Le.error,ge),P&&It&&!(Le!=null&&Le.loading)&&!(Le!=null&&Le.error)&&t.jsx(It,{context:s,parent:a,link:P,activeItemId:Te,onOpenDetail:ft,onBackToList:Qe})]})]})]})}const Ui={info:{color:"#2563eb",background:"rgba(59, 130, 246, 0.1)",border:"rgba(59, 130, 246, 0.24)",icon:t.jsx(q.HiInformationCircle,{className:"h-5 w-5"})},success:{color:"#047857",background:"rgba(16, 185, 129, 0.1)",border:"rgba(16, 185, 129, 0.24)",icon:t.jsx(q.HiCheckCircle,{className:"h-5 w-5"})},warning:{color:"#b45309",background:"rgba(245, 158, 11, 0.12)",border:"rgba(245, 158, 11, 0.26)",icon:t.jsx(q.HiExclamationTriangle,{className:"h-5 w-5"})},danger:{color:"var(--danger)",background:"var(--danger-bg)",border:"color-mix(in srgb, var(--danger) 20%, var(--border))",icon:t.jsx(q.HiExclamationCircle,{className:"h-5 w-5"})},neutral:{color:"var(--text-secondary)",background:"var(--bg-input)",border:"var(--border)",icon:t.jsx(q.HiInformationCircle,{className:"h-5 w-5"})}};function Vi({variant:e="info",title:r,children:n,icon:a,action:s,onDismiss:l,className:i=""}){const c=Ui[e];return t.jsxs("div",{role:e==="danger"||e==="warning"?"alert":"status",className:`flex items-start gap-3 rounded-lg border px-3 py-3 ${i}`,style:{background:c.background,borderColor:c.border},children:[t.jsx("div",{className:"mt-0.5 shrink-0",style:{color:c.color},children:a??c.icon}),t.jsxs("div",{className:"min-w-0 flex-1",children:[r&&t.jsx("div",{className:"text-sm font-semibold text-[var(--text-main)]",children:r}),n&&t.jsx("div",{className:"mt-0.5 text-sm leading-5 text-[var(--text-secondary)]",children:n}),s&&t.jsx("div",{className:"mt-3",children:s})]}),l&&t.jsx(Ue,{variant:"icon",size:"xs","aria-label":"Cerrar alerta",onClick:l,className:"-mr-1 -mt-1",children:t.jsx(q.HiXMark,{className:"h-4 w-4"})})]})}const Vo=["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"],Yi=["Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"],Xi=["lu","ma","mi","ju","vi","sá","do"],Yo=6;function Ea(e,r,n){return`${e}-${String(r).padStart(2,"0")}-${String(n).padStart(2,"0")}`}function Ki(){const e=new Date;return Ea(e.getFullYear(),e.getMonth()+1,e.getDate())}function Xo(e){const[r,n,a]=e.split("-").map(Number);return{year:r,month:n,day:a}}function Gi(e){if(!e)return"Seleccionar fecha";const{year:r,month:n,day:a}=Xo(e);return!r||!n||!a?"Seleccionar fecha":`${String(a).padStart(2,"0")} ${Vo[n-1]} ${r}`}function Zi({value:e,onChange:r,minDate:n,displayMode:a="inline",className:s=""}){const l=Ki(),c=Xo(e||l),d=a==="popover",[u,m]=o.useState(!1),b=o.useRef(null),[f,g]=o.useState({horizontal:"left",vertical:"bottom"}),[v,k]=o.useState(c.year),[h,C]=o.useState(c.month),[M,y]=o.useState("days"),x=16,[w,N]=o.useState(0),A=v-7+w,T=Array.from({length:x},(R,V)=>A+V);o.useEffect(()=>{if(!d||!u||!b.current)return;const R=b.current.getBoundingClientRect(),V=8,B=280,le=340,j=R.left+B>window.innerWidth-V,W=R.right-B>=V,ae=R.bottom+8+le>window.innerHeight-V,H=R.top-8-le>=V;g({horizontal:j&&W?"right":"left",vertical:ae&&H?"top":"bottom"})},[d,u]),o.useEffect(()=>{if(!d||!u)return;function R(B){b.current&&(b.current.contains(B.target)||m(!1))}function V(B){B.key==="Escape"&&m(!1)}return document.addEventListener("mousedown",R),document.addEventListener("keydown",V),()=>{document.removeEventListener("mousedown",R),document.removeEventListener("keydown",V)}},[d,u]);function U(){h===1?(k(R=>R-1),C(12)):C(R=>R-1)}function K(){h===12?(k(R=>R+1),C(1)):C(R=>R+1)}const Z=(new Date(v,h-1,1).getDay()+6)%7,L=new Date(v,h,0).getDate(),Q=[...Array(Z).fill(null),...Array.from({length:L},(R,V)=>V+1)];for(;Q.length<Yo*7;)Q.push(null);const z=Q.slice(0,Yo*7);function se(R){const V=Ea(v,h,R);n&&V<n||(r(V),d&&m(!1))}const re=t.jsx("div",{className:`bonsaif-calendar bonsaif-calendar-picker ${s}`.trim(),children:t.jsxs("div",{className:"bonsaif-cal-shell",children:[t.jsx("div",{className:"bonsaif-cal-toolbar",children:M==="days"?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn",onClick:U,"aria-label":"Mes anterior",children:t.jsx(q.HiChevronLeft,{size:16})}),t.jsxs("button",{type:"button",className:"bonsaif-cal-title-btn",onClick:()=>{y("years"),N(0)},children:[t.jsxs("span",{className:"bonsaif-cal-title",children:[Vo[h-1]," ",v]}),t.jsx(q.HiChevronDown,{size:13})]}),t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn",onClick:K,"aria-label":"Mes siguiente",children:t.jsx(q.HiChevronRight,{size:16})})]}):t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn",onClick:()=>N(R=>R-x),"aria-label":"Años anteriores",children:t.jsx(q.HiChevronLeft,{size:16})}),t.jsx("button",{type:"button",className:"bonsaif-cal-title-btn",onClick:()=>y("days"),children:t.jsxs("span",{className:"bonsaif-cal-title",children:[T[0]," – ",T[T.length-1]]})}),t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn",onClick:()=>N(R=>R+x),"aria-label":"Años siguientes",children:t.jsx(q.HiChevronRight,{size:16})})]})}),M==="years"?t.jsxs("div",{className:"bonsaif-cal-picker-years",children:[t.jsx("div",{className:"bonsaif-cal-picker-months",children:Yi.map((R,V)=>{const B=V+1===h;return t.jsx("button",{type:"button",className:`bonsaif-cal-pill-btn${B?" is-active":""}`,onClick:()=>C(V+1),children:R},R)})}),t.jsx("div",{className:"bonsaif-cal-picker-year-grid",children:T.map(R=>{const V=R===v,B=R===new Date().getFullYear();return t.jsx("button",{type:"button",className:`bonsaif-cal-pill-btn${V?" is-active":""}${B&&!V?" is-today":""}`,onClick:()=>{k(R),y("days")},children:R},R)})})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bonsaif-multi-weekdays bonsaif-cal-picker-weekdays",children:Xi.map(R=>t.jsx("div",{className:"bonsaif-multi-weekday",children:R},R))}),t.jsx("div",{className:"bonsaif-cal-picker-days",children:z.map((R,V)=>{if(R===null)return t.jsx("div",{className:"bonsaif-multi-day bonsaif-multi-day-hidden"},V);const B=Ea(v,h,R),le=B===e,j=B===l,W=!!(n&&B<n);return t.jsx("div",{className:`bonsaif-multi-day${le?" bonsaif-multi-day-selected":""}${j?" bonsaif-multi-day-today":""}${W?" bonsaif-multi-day-disabled":""}`,children:t.jsx("button",{type:"button",className:"bonsaif-multi-day-btn",disabled:W,"aria-pressed":le,onClick:()=>!W&&se(R),children:R})},V)})})]})]})});return d?t.jsxs("div",{ref:b,className:`relative w-full ${s}`.trim(),children:[t.jsxs("button",{type:"button",onClick:()=>m(R=>!R),className:"bonsaif-cal-trigger","data-open":u?"true":"false",children:[t.jsxs("span",{className:"inline-flex items-center gap-2 min-w-0",children:[t.jsx(q.HiCalendarDays,{className:"w-4 h-4 text-[var(--text-muted)]"}),t.jsx("span",{className:"truncate",children:Gi(e)})]}),t.jsx(q.HiChevronDown,{className:`w-4 h-4 text-[var(--text-muted)] transition-transform ${u?"rotate-180":""}`})]}),u&&t.jsx("div",{className:"absolute z-50",style:{...f.horizontal==="left"?{left:0}:{right:0},...f.vertical==="bottom"?{top:"calc(100% + 8px)"}:{bottom:"calc(100% + 8px)"}},children:re})]}):re}const Qi={sm:"h-4 w-4",md:"h-5 w-5"};function Ji(e,r){if(typeof e=="function"){e(r);return}e&&(e.current=r)}const vn=o.forwardRef(function({label:r,description:n,error:a,size:s="md",indeterminate:l=!1,className:i="",containerClassName:c="",disabled:d,...u},m){const b=o.useRef(null);return o.useEffect(()=>{b.current&&(b.current.indeterminate=l)},[l]),t.jsxs("label",{className:`group inline-flex items-start gap-2.5 ${d?"cursor-not-allowed opacity-60":"cursor-pointer"} ${c}`,children:[t.jsxs("span",{className:"relative mt-0.5 inline-flex shrink-0",children:[t.jsx("input",{...u,ref:f=>{b.current=f,Ji(m,f)},type:"checkbox",disabled:d,"aria-checked":l?"mixed":u["aria-checked"],"aria-invalid":!!a||u["aria-invalid"],className:`peer ${Qi[s]} appearance-none rounded border border-[var(--border)] bg-[var(--bg-input)] transition-colors checked:border-[var(--primary)] checked:bg-[var(--primary)] focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--primary)]/40 ${i}`}),t.jsx(q.HiCheck,{className:"pointer-events-none absolute left-1/2 top-1/2 h-3.5 w-3.5 -translate-x-1/2 -translate-y-1/2 scale-75 text-[var(--primary-fg)] opacity-0 transition peer-checked:scale-100 peer-checked:opacity-100 peer-aria-checked:mixed:scale-100 peer-aria-checked:mixed:opacity-100"})]}),(r||n||a)&&t.jsxs("span",{className:"min-w-0",children:[r&&t.jsx("span",{className:"block text-sm font-medium leading-5 text-[var(--text-main)]",children:r}),n&&!a&&t.jsx("span",{className:"block text-xs leading-5 text-[var(--text-muted)]",children:n}),a&&t.jsx("span",{className:"block text-xs leading-5 text-[var(--danger)]",children:a})]})]})});function Ko(e){const r=document.createElement("textarea");r.value=e,r.style.position="fixed",r.style.opacity="0",r.style.pointerEvents="none",document.body.appendChild(r),r.select(),document.execCommand("copy"),document.body.removeChild(r)}async function Ri(e){var r;if((r=navigator.clipboard)!=null&&r.writeText){await navigator.clipboard.writeText(e);return}Ko(e)}function ec(e){return typeof e=="function"?e():e}function Ma({value:e,resetDelay:r=2e3,title:n,copiedTitle:a="Copiado",copiedLabel:s,icon:l=t.jsx(q.HiClipboardDocument,{size:14}),copiedIcon:i=t.jsx(q.HiCheck,{size:14}),stopPropagation:c=!0,onCopied:d,onCopyError:u,className:m="",style:b,children:f,onClick:g,type:v="button",...k}){const[h,C]=o.useState(!1),M=o.useRef(null);o.useEffect(()=>()=>{M.current&&window.clearTimeout(M.current)},[]);function y(w){C(!0),d==null||d(w),M.current&&window.clearTimeout(M.current),M.current=window.setTimeout(()=>{C(!1),M.current=null},r)}async function x(w){var A;if(c&&w.stopPropagation(),g==null||g(w),w.defaultPrevented)return;const N=ec(e);if(N)try{await Ri(N),y(N)}catch(T){try{Ko(N),y(N)}catch(U){u==null||u(U,N);return}(A=navigator.clipboard)!=null&&A.writeText||u==null||u(T,N)}}return t.jsxs("button",{...k,type:v,onClick:x,title:h?a:n,"aria-label":k["aria-label"]??(h?a:n),"data-copied":h?"true":void 0,className:`relative inline-flex h-7 shrink-0 items-center justify-center gap-1.5 rounded-md transition-all duration-200 ${f?"min-w-7 px-2":"w-7"} ${m}`,style:{cursor:"pointer",background:h?"rgba(22,163,74,0.15)":"var(--bg-card)",border:h?"1px solid rgba(22,163,74,0.4)":"1px solid var(--border)",color:h?"#16a34a":"var(--text-secondary)",boxShadow:h?"0 0 0 3px rgba(22,163,74,0.12)":"none",...b},children:[t.jsx("span",{className:"inline-flex items-center justify-center transition-all duration-150",style:{transform:h?"scale(1.15)":"scale(1)"},children:h?i:l}),f&&t.jsx("span",{className:"text-xs font-semibold leading-none",children:h?s??f:f})]})}function tc({code:e,children:r,title:n="Codigo",language:a,copyLabel:s="Copiar",copiedLabel:l="Copiado",className:i="",style:c,onCopied:d}){const u=(e??r??"").trim();return t.jsxs("div",{className:`overflow-hidden rounded-lg border ${i}`,style:{borderColor:"rgba(148, 163, 184, 0.22)",background:"#0f172a",color:"#e2e8f0",...c},children:[t.jsxs("div",{className:"flex min-h-9 items-center justify-between gap-3 border-b px-3 py-1.5",style:{borderColor:"rgba(148, 163, 184, 0.18)",background:"#111827",color:"#94a3b8"},children:[t.jsx("span",{className:"min-w-0 truncate text-[11px] font-black uppercase tracking-[0.08em]",children:n}),t.jsx(Ma,{value:u,title:"Copiar codigo",copiedTitle:"Codigo copiado",copiedLabel:l,onCopied:d,className:"h-7 min-w-[72px] px-2",style:{background:"#182235",border:"1px solid rgba(148, 163, 184, 0.28)",color:"#f8fafc"},children:s})]}),t.jsx("pre",{className:"m-0 overflow-x-auto p-3 text-xs leading-6",style:{background:"#0f172a",color:"#e2e8f0",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace'},children:t.jsx("code",{className:a?`language-${a}`:void 0,children:u})})]})}function Ta(e){if(e!==void 0)return typeof e=="number"?`${e}px`:e}function $a(e){return e.normalize("NFD").replace(new RegExp("\\p{M}","gu"),"").toLowerCase()}function rc(e,r){if(!r.trim())return!0;const n=$a(r);return $a(e.label).includes(n)||!!(e.sublabel&&$a(e.sublabel).includes(n))}function ar({value:e,onChange:r,options:n,status:a="default",ariaLabel:s,triggerVariant:l="default",showSelectedSublabel:i=!0,placeholder:c="Seleccionar…",emptyLabel:d,disabled:u=!1,className:m="",style:b,dropdownMinWidth:f,height:g=40,padding:v="0 10px",searchable:k=!0,minOptionsForSearch:h=6}){const[C,M]=o.useState(!1),[y,x]=o.useState(""),[w,N]=o.useState(-1),[A,T]=o.useState(!1),[U,K]=o.useState({}),Z=o.useRef(null),L=o.useRef(null),Q=o.useRef(null),z=o.useRef(null),se=k&&n.length>=h,re=n.find(G=>G.value===e)??null,R=l==="ghost",V=a==="error"?"var(--danger)":C?"var(--primary)":"var(--border)",B=se&&y.trim()?n.filter(G=>rc(G,y)):n,le=o.useCallback(()=>{const G=Z.current;if(!G)return;const X=G.getBoundingClientRect(),S=se?272:212,O=window.innerHeight-X.bottom,I=O<S&&X.top>O;K({position:"fixed",left:X.left,top:I?void 0:X.bottom+4,bottom:I?window.innerHeight-X.top+4:void 0,width:X.width,minWidth:Ta(f),zIndex:9999})},[f,se]);o.useEffect(()=>T(!0),[]),o.useEffect(()=>{if(!C)return;function G(X){var O,I;const S=X.target;!((O=Z.current)!=null&&O.contains(S))&&!((I=L.current)!=null&&I.contains(S))&&(M(!1),x(""))}return document.addEventListener("mousedown",G),()=>document.removeEventListener("mousedown",G)},[C]),o.useEffect(()=>{C&&(N(-1),le(),se&&setTimeout(()=>{var G;return(G=Q.current)==null?void 0:G.focus()},0))},[C,se,le]),o.useEffect(()=>{if(C)return window.addEventListener("resize",le),window.addEventListener("scroll",le,!0),()=>{window.removeEventListener("resize",le),window.removeEventListener("scroll",le,!0)}},[C,le]),o.useEffect(()=>{if(w<0||!z.current)return;const G=z.current.children[w];G==null||G.scrollIntoView({block:"nearest"})},[w]);const j=o.useCallback(G=>{r(G),M(!1),x("")},[r]),W=o.useRef(C);W.current=C;const ae=o.useRef(B);ae.current=B;const H=o.useRef(w);H.current=w;const D=o.useRef(d);D.current=d;const $=o.useRef(j);$.current=j,o.useEffect(()=>{function G(X){var te,P;const S=document.activeElement,O=((te=Z.current)==null?void 0:te.contains(S))??!1,I=((P=L.current)==null?void 0:P.contains(S))??!1;if(!(!O&&!I)){if(!W.current){(X.key==="Enter"||X.key===" "||X.key==="ArrowDown")&&(X.preventDefault(),M(!0));return}switch(X.key){case"ArrowDown":X.preventDefault(),N(ce=>Math.min(ce+1,ae.current.length-1));break;case"ArrowUp":X.preventDefault(),N(ce=>Math.max(ce-1,D.current?-1:0));break;case"Enter":{X.preventDefault();const ce=H.current,he=ae.current;ce===-1&&D.current?$.current(""):he[ce]&&!he[ce].disabled&&$.current(he[ce].value);break}case"Escape":X.preventDefault(),X.stopPropagation(),M(!1),x("");break}}}return document.addEventListener("keydown",G),()=>document.removeEventListener("keydown",G)},[]);const oe=t.jsxs("div",{ref:L,"data-bonsaif-select-dropdown":"true",className:"rounded-xl shadow-xl overflow-hidden",style:{...U,background:"var(--bg-card)",border:"1px solid var(--border)"},children:[se&&t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",style:{borderBottom:"1px solid var(--border)"},children:[t.jsx(q.HiMagnifyingGlass,{className:"w-3.5 h-3.5 flex-shrink-0",style:{color:"var(--text-muted)"}}),t.jsx("input",{ref:Q,value:y,onChange:G=>{x(G.target.value),N(-1)},placeholder:"Buscar…",className:"min-w-0 flex-1 text-sm bg-transparent outline-none",style:{color:"var(--text-main)"}}),y&&t.jsx("button",{type:"button",onMouseDown:G=>{G.preventDefault(),x("")},children:t.jsx(q.HiXMark,{className:"w-3.5 h-3.5",style:{color:"var(--text-muted)"}})})]}),t.jsxs("ul",{ref:z,role:"listbox",className:"overflow-y-auto",style:{maxHeight:se?220:180,scrollbarWidth:"thin",scrollbarColor:"var(--border) transparent",overscrollBehavior:"contain"},children:[d&&t.jsx("li",{role:"option","aria-selected":e==="",onMouseDown:G=>{G.preventDefault(),j("")},onMouseEnter:()=>N(-1),className:"flex items-center gap-2 px-3 py-2 cursor-pointer text-sm transition-colors",style:{background:w===-1&&!y.trim()?"var(--bg-hover)":"transparent",color:"var(--text-muted)",fontStyle:"italic"},children:d}),B.map((G,X)=>{const O=X===w,I=G.value===e;return t.jsxs("li",{role:"option","aria-selected":I,onMouseDown:te=>{te.preventDefault(),G.disabled||j(G.value)},onMouseEnter:()=>!G.disabled&&N(X),className:"flex items-center gap-2 px-3 py-2 cursor-pointer text-sm transition-colors",style:{background:O?"var(--bg-hover)":I?"color-mix(in srgb, var(--primary) 6%, transparent)":"transparent",color:G.disabled?"var(--text-muted)":"var(--text-main)",cursor:G.disabled?"not-allowed":"pointer",boxShadow:I?"inset 2px 0 0 var(--primary)":void 0},children:[G.color&&t.jsx("span",{className:"flex-shrink-0 w-2.5 h-2.5 rounded-full",style:{background:G.color}}),t.jsxs("span",{className:"min-w-0 flex flex-1 items-baseline gap-1 overflow-hidden",children:[t.jsx("span",{className:"truncate",children:G.label}),G.sublabel&&t.jsx("span",{className:"min-w-0 flex-shrink truncate",style:{color:"var(--text-muted)",fontSize:12},children:G.sublabel})]}),G.badge&&t.jsx("span",{className:"text-xs flex-shrink-0",style:{color:"var(--text-muted)"},children:G.badge})]},G.value)}),B.length===0&&t.jsx("li",{className:"px-3 py-4 text-sm text-center",style:{color:"var(--text-muted)"},children:"Sin resultados"})]})]});return t.jsxs("div",{ref:Z,className:`relative ${m||"w-full"}`,style:b,children:[t.jsxs("button",{type:"button",disabled:u,onClick:()=>!u&&M(G=>!G),className:"flex w-full items-center gap-2 rounded-lg text-left text-sm transition-colors focus:outline-none",style:{height:Ta(g),padding:Ta(v),background:R?"transparent":"var(--bg-input)",color:re?"var(--text-main)":"var(--text-muted)",border:R?"1px solid transparent":`1px solid ${V}`,opacity:u?.5:1,cursor:u?"not-allowed":"pointer"},"aria-haspopup":"listbox","aria-expanded":C,"aria-label":s,children:[(re==null?void 0:re.color)&&t.jsx("span",{className:"flex-shrink-0 w-2.5 h-2.5 rounded-full",style:{background:re.color}}),t.jsx("span",{className:"min-w-0 flex flex-1 items-baseline gap-1 overflow-hidden",children:re?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"truncate",children:re.label}),i&&re.sublabel&&t.jsx("span",{className:"min-w-0 flex-shrink truncate",style:{color:"var(--text-muted)",fontSize:12},children:re.sublabel})]}):t.jsx("span",{className:"truncate",children:c})}),re&&d?t.jsx("span",{role:"button",tabIndex:-1,onMouseDown:G=>{G.preventDefault(),G.stopPropagation(),j("")},className:"flex-shrink-0 rounded-full p-0.5 transition-colors hover:bg-black/10",style:{color:"var(--text-muted)"},children:t.jsx(q.HiXMark,{className:"w-3 h-3"})}):t.jsx(q.HiChevronDown,{className:"flex-shrink-0 w-4 h-4 transition-transform",style:{color:"var(--text-muted)",transform:C?"rotate(180deg)":"rotate(0deg)"}})]}),C&&A&&dt.createPortal(oe,document.body)]})}function yn(e){if(e!==void 0)return typeof e=="number"?`${e}px`:e}function nc({value:e,onChange:r,placeholder:n="Buscar...",className:a="",height:s=40,padding:l="0 10px 0 30px",iconLeft:i=10}){return t.jsxs("div",{className:`relative ${a}`,children:[t.jsx(q.HiMagnifyingGlass,{className:"absolute top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-[var(--text-muted)] pointer-events-none",style:{left:yn(i)}}),t.jsx("input",{type:"text",value:e,onChange:c=>r(c.target.value),placeholder:n,className:"w-full rounded-lg border border-[var(--border)] [background:var(--bg-card)] text-sm text-[var(--text-main)] placeholder:text-[var(--text-muted)] outline-none transition-[border-color,box-shadow] focus:border-primary focus:ring-2 focus:ring-primary/20",style:{height:yn(s),padding:yn(l)}})]})}function ac({value:e,onChange:r,options:n,placeholder:a,icon:s,className:l="",height:i=40,padding:c,iconLeft:d=10,searchable:u=!0}){const m=s?n.map((b,f)=>f===0&&!b.color?{...b,sublabel:b.sublabel??void 0}:b):n;return t.jsxs("div",{className:`relative ${l}`,children:[s&&t.jsx("span",{className:"pointer-events-none absolute top-1/2 z-10 -translate-y-1/2 text-[var(--text-muted)]",style:{left:yn(d)},children:s}),t.jsx(ar,{value:e,onChange:r,options:m,placeholder:a,searchable:u,minOptionsForSearch:5,height:i,padding:c??(s?"0 10px 0 30px":"0 10px"),className:"[&>button]:text-sm [&>button]:[background:var(--bg-card)]"})]})}const oc={sm:"24rem",md:"28rem",lg:"32rem",xl:"40rem","2xl":"48rem","4xl":"56rem","5xl":"64rem"},xn=180,sc="bg-[color-mix(in_srgb,var(--bg-main)_72%,transparent)] backdrop-blur-sm";function Aa({open:e,onClose:r,title:n,subtitle:a,leadingIcon:s,headerActions:l,footer:i,children:c,size:d="md",maxWidth:u,zIndex:m=1e3,closeOnBackdrop:b=!0,closeOnEscape:f=!0,showCloseButton:g=!0,placement:v="center",bodyClassName:k="px-6 py-5",panelClassName:h="",backdropClassName:C=sc,contentClassName:M="p-4",ariaLabel:y,frameless:x=!1,disabled:w=!1}){const[N,A]=o.useState(!1),[T,U]=o.useState(!1),K=o.useRef(null);if(o.useEffect(()=>(e?(K.current&&clearTimeout(K.current),A(!0),requestAnimationFrame(()=>requestAnimationFrame(()=>U(!0)))):(U(!1),K.current=setTimeout(()=>A(!1),xn+40)),()=>{K.current&&clearTimeout(K.current)}),[e]),o.useEffect(()=>{if(e)return document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}},[e]),o.useEffect(()=>{if(!e||!f)return;const re=R=>{R.key==="Escape"&&r()};return window.addEventListener("keydown",re),()=>window.removeEventListener("keydown",re)},[f,r,e]),!N)return null;const Z=n||a||s||l||g,L=u??oc[d],Q=v==="bottom-mobile"?"items-end sm:items-center justify-center p-0 sm:p-4":"items-center justify-center",z=v==="bottom-mobile"?"rounded-t-2xl sm:rounded-2xl":"rounded-2xl",se=T?"translateY(0) scale(1)":v==="bottom-mobile"?"translateY(16px) scale(0.98)":"translateY(10px) scale(0.96)";return dt.createPortal(t.jsxs("div",{role:"dialog","aria-modal":"true","data-bonsaif-overlay":"true","aria-label":y??n,className:`fixed inset-0 flex ${Q} ${M}`,style:{zIndex:m},children:[t.jsx("div",{className:`absolute inset-0 ${C}`,onClick:b?r:void 0,style:{opacity:T?1:0,transition:`opacity ${xn}ms ease`}}),t.jsxs("div",{className:`relative z-10 flex max-h-[92dvh] w-full flex-col overflow-hidden ${x?"shadow-none":"shadow-2xl"} ${z} ${h}`,style:{maxWidth:L,background:x?"transparent":"var(--bg-card)",border:x?"none":"1px solid var(--border)",opacity:T?1:0,transform:se,transition:`opacity ${xn}ms ease, transform ${xn}ms ease`},onClick:re=>re.stopPropagation(),children:[w&&t.jsx("div",{className:"absolute inset-0 z-[1002] cursor-not-allowed rounded-2xl",style:{background:"color-mix(in srgb, var(--bg-card, #ffffff) 60%, transparent)",backdropFilter:"blur(2px)"}}),Z&&t.jsxs("div",{className:"flex flex-shrink-0 items-center justify-between gap-3 px-6 py-4",style:{borderBottom:"1px solid var(--border)"},children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[s&&t.jsx("div",{className:"flex-shrink-0",children:s}),(n||a)&&t.jsxs("div",{className:"min-w-0",children:[n&&t.jsx("h2",{className:"truncate text-base font-semibold",style:{color:"var(--text-main)"},children:n}),a&&t.jsx("p",{className:"truncate text-xs",style:{color:"var(--text-muted)"},children:a})]})]}),t.jsxs("div",{className:"flex flex-shrink-0 items-center gap-2",children:[l,g&&t.jsx(Ue,{variant:"icon",onClick:r,title:"Cerrar",children:t.jsx(q.HiXMark,{className:"h-5 w-5"})})]})]}),t.jsx("div",{className:`min-h-0 flex-1 overflow-y-auto ${k}`,children:c}),i&&t.jsx("div",{className:"flex flex-shrink-0 justify-end gap-2 px-6 py-4",style:{borderTop:"1px solid var(--border)"},children:i})]})]}),document.body)}const lc={danger:{iconBg:"rgba(239,68,68,0.12)",iconColor:"var(--danger)",btnBg:"var(--danger)",btnColor:"#fff"},warning:{iconBg:"rgba(245,158,11,0.12)",iconColor:"var(--warning)",btnBg:"var(--warning)",btnColor:"#fff"},primary:{iconBg:"rgba(59,130,246,0.12)",iconColor:"var(--primary)",btnBg:"var(--primary)",btnColor:"#fff"}};function ic({open:e,title:r,description:n,confirmLabel:a="Confirmar",cancelLabel:s="Cancelar",variant:l="danger",closeOnBackdrop:i=!0,onConfirm:c,onCancel:d}){const u=lc[l];return t.jsx(Aa,{open:e,onClose:d,size:"md",zIndex:9998,showCloseButton:!1,bodyClassName:"p-0",panelClassName:"overflow-visible",ariaLabel:r,closeOnBackdrop:i,children:t.jsxs("div",{className:"relative px-6 pb-6 pt-6",children:[t.jsx(Ue,{variant:"icon",onClick:d,className:"absolute right-3 top-3 h-8 w-8 hover:opacity-70",style:{color:"var(--text-muted)"},"aria-label":"Cancelar",children:t.jsx(q.HiXMark,{className:"h-4 w-4"})}),t.jsxs("div",{className:"flex gap-3 pr-8",children:[t.jsx("div",{className:"mt-0.5 flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-xl",style:{background:u.iconBg},children:t.jsx(q.HiExclamationTriangle,{className:"h-5 w-5",style:{color:u.iconColor}})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("h2",{className:"text-base font-semibold leading-snug",style:{color:"var(--text-main)"},children:r}),n?t.jsx("div",{className:"mt-1.5 text-sm leading-relaxed",style:{color:"var(--text-muted)"},children:n}):null]})]}),t.jsxs("div",{className:"mt-6 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[t.jsx(Ue,{variant:"secondary",onClick:d,className:"w-full sm:w-auto sm:min-w-[7.5rem]",style:{background:"var(--bg-input)"},children:s}),t.jsx(Ue,{variant:"danger",onClick:c,className:"w-full sm:w-auto sm:min-w-[7.5rem]",style:{background:u.btnBg,color:u.btnColor,borderColor:"transparent"},children:a})]})]})})}function cc(e){return e?typeof e=="function"?e():e:""}function dc(e){return/^https?:\/\//i.test(e)}function Go(e,r){try{return new URL(e,r).toString()}catch{return e}}function uc(e,r,n,a=!1){const s=typeof e=="function"?e():e,l=r?r(s):s;if(!l||dc(l))return l;const i=cc(n);return i?Go(l,i):a&&typeof window<"u"?Go(l,window.location.origin):l}function fc({url:e,resolveUrl:r,baseUrl:n,useWindowOriginForRelative:a=!1,title:s="Copiar link",copiedTitle:l="Link copiado",icon:i=t.jsx(q.HiLink,{className:"h-3.5 w-3.5"}),...c}){return t.jsx(Ma,{...c,value:()=>uc(e,r,n,a),title:s,copiedTitle:l,icon:i})}const wn=[25,50,100,200,500];let Et={dataTable:{pageSizeOptions:[...wn]}};function bc(){if(typeof window>"u")return;const r=window.__BONSAIF_DATA_TABLE_PREFERENCES_ENDPOINT__;return typeof r=="string"&&r.trim().length>0?r.trim().replace(/\/+$/,""):void 0}function La(){const e=Et.dataTable.preferencesEndpoint,r=bc();return e&&e.trim().length>0?e.trim().replace(/\/+$/,""):r}function mc(e){if(!Array.isArray(e))return[...wn];const r=Array.from(new Set(e.map(n=>typeof n=="number"?Math.floor(n):Number.NaN).filter(n=>Number.isFinite(n)&&n>0)));return r.length>0?r:[...wn]}function Zo(e){if(typeof e!="string")return;const r=e.trim();if(r)return r.replace(/\/+$/,"")}function pc(e){if(!e||typeof e!="object"||!e.dataTable)return;const r=Zo(e.dataTable.preferencesEndpoint);Et={...Et,dataTable:{...Et.dataTable,pageSizeOptions:mc(e.dataTable.pageSizeOptions),preferencesEndpoint:r??Et.dataTable.preferencesEndpoint}}}function hc(){return{dataTable:{pageSizeOptions:[...Et.dataTable.pageSizeOptions]}}}function Vr(){return[...Et.dataTable.pageSizeOptions]}function gc(){Et={dataTable:{pageSizeOptions:[...wn]}}}function vc(e){Et={...Et,dataTable:{...Et.dataTable,preferencesEndpoint:Zo(e)}}}const Nn=[{value:"equals",label:"Igual a",valueMode:"single"},{value:"notEquals",label:"No es igual a",valueMode:"single"},{value:"greaterThan",label:"Mayor que",valueMode:"single"},{value:"greaterThanOrEqual",label:"Mayor o igual que",valueMode:"single"},{value:"lessThan",label:"Menor que",valueMode:"single"},{value:"lessThanOrEqual",label:"Menor o igual que",valueMode:"single"},{value:"between",label:"Entre",valueMode:"between"},{value:"top10",label:"10 superiores",valueMode:"none"},{value:"bottom10",label:"10 inferiores",valueMode:"none"},{value:"aboveAverage",label:"Sobre promedio",valueMode:"none"},{value:"belowAverage",label:"Bajo promedio",valueMode:"none"}],yc=Nn.map(e=>({value:e.value,label:e.label})),xc=12,wc={layout:!0,filters:!1,sort:!1,bql:!1,pagination:!0},Qo={layout:!0,filters:!0,sort:!0,bql:!0,pagination:!0},Nc="bonsaif-ui:datatable:",kc="[&_button]:h-7 [&_button]:min-h-0 [&_button]:gap-1 [&_button]:px-2 [&_button]:text-xs [&_button_svg]:h-3.5 [&_button_svg]:w-3.5 [&_button[data-icon=true]]:w-7 [&_button[data-icon=true]]:px-0",Sc=[],Cc=52;function Pt(e){if(!e)return 150;const r=parseInt(e,10);return isNaN(r)||r<=0?150:r}function Jo(e){return!!(e&&(Array.isArray(e.columnOrder)&&e.columnOrder.length>0||e.columnWidths&&Object.keys(e.columnWidths).length>0||Array.isArray(e.hiddenColumnKeys)&&e.hiddenColumnKeys.length>0||e.filters&&Object.keys(e.filters).length>0||e.conditionFilters&&Object.keys(e.conditionFilters).length>0||e.sort||typeof e.bql=="string"||Array.isArray(e.bqlHistory)&&e.bqlHistory.length>0||typeof e.pageSize=="number"))}function Ro(e){return`${Nc}${e}`}function kn(e){try{const r=window.localStorage.getItem(Ro(e));if(!r)return null;const n=JSON.parse(r);return n&&typeof n=="object"?n:null}catch{return null}}function Ec(e,r){try{window.localStorage.setItem(Ro(e),JSON.stringify(r))}catch{}}function Mc(e,r){if(e===!0)return{...Qo};if(e===!1)return{layout:!1,filters:!1,sort:!1,bql:!1,pagination:!1};if(r&&e==null)return{...Qo};const n={...wc,...e??{}};return r&&(typeof e!="object"||e.pagination!==!1)&&(n.pagination=!0),n}function es(...e){return e.reduce((r,n)=>({...r,...n??{}}),{})}function Da(e,r,n){return typeof e!="number"||e<=0?n:Zr(r).includes(e)?e:n}function Yr(e){if(!e||typeof e!="object")return!1;const r=e;return typeof r.key=="string"&&(r.dir==="asc"||r.dir==="desc")}function Xr(e,r){if(!e||typeof e!="object"||Array.isArray(e))return{};const n=Object.entries(e).flatMap(([a,s])=>{if(!r.has(a)||!Array.isArray(s))return[];const l=s.filter(i=>typeof i=="string");return l.length>0?[[a,l]]:[]});return Object.fromEntries(n)}function Kr(e,r){if(!e||typeof e!="object"||Array.isArray(e))return{};const n=new Set(Nn.map(s=>s.value)),a=Object.entries(e).flatMap(([s,l])=>{if(!r.has(s)||!l||typeof l!="object")return[];const i=l;return!i.operator||!n.has(i.operator)?[]:[[s,{operator:i.operator,value:typeof i.value=="string"?i.value:"",valueTo:typeof i.valueTo=="string"?i.valueTo:""}]]});return Object.fromEntries(a)}function yt(e,r){if(or(e))return Cc;const n=e.minWidth??80,a=e.maxWidth??1/0;return Math.min(a,Math.max(n,r))}function Tc(e){const r=window.getComputedStyle(e);return parseFloat(r.paddingLeft)+parseFloat(r.paddingRight)}function or(e){return e.key==="actions"||e.key==="acciones"?!0:typeof e.header=="string"&&e.header.trim().toLowerCase()==="acciones"}function Ia(e){return e.sticky===!0}function ts(e){return!(e.reorderable===!1||e.sticky&&e.reorderable!==!0)}function qt(e,r){const n=r.filter(Ia).map(i=>i.key);if(n.length===0)return e;const a=new Set(n),s=n.filter(i=>e.includes(i)),l=e.filter(i=>!a.has(i));return[...s,...l]}function $c(e,r){if(r<=7)return Array.from({length:r},(a,s)=>s+1);const n=[1];e>3&&n.push("...");for(let a=Math.max(2,e-1);a<=Math.min(r-1,e+1);a++)n.push(a);return e<r-2&&n.push("..."),n.push(r),n}function Ut(e,r){var i;const n=new Set(r.filter(c=>c.hideable!==!1).map(c=>c.key)),a=Array.from(new Set(e??[])).filter(c=>n.has(c));if(r.filter(c=>!a.includes(c.key)).length>0)return a;const l=(i=r.find(c=>c.hideable!==!1))==null?void 0:i.key;return l?a.filter(c=>c!==l):[]}function Ac(e){return e==null||e===""?"(Vacio)":e instanceof Date?e.toLocaleDateString():String(e)}function gr(e){return e==null||typeof e=="boolean"?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(gr).join(" ").trim():o.isValidElement(e)?gr(e.props.children):""}function Sn(e,r){const n=e.filterValue?e.filterValue(r):e.sortKey?r[e.sortKey]:e.cell(r);return typeof n=="string"||typeof n=="number"||typeof n=="boolean"||n===null||n===void 0||n instanceof Date?Ac(n):gr(n).trim()}function Gr(e){const r=e.replace(/,/g,"").trim();if(!r)return null;const n=Number(r);return Number.isFinite(n)?n:null}function vr(e,r){const n=Gr(e),a=Gr(r);return n!==null&&a!==null?n-a:e.localeCompare(r,void 0,{numeric:!0,sensitivity:"base"})}function Zr(e){const r=Array.from(new Set(e.map(n=>Math.floor(n)).filter(n=>Number.isFinite(n)&&n>0)));return r.length>0?r:Vr()}function Lc(e,r,n){var i,c;const a=((i=r.value)==null?void 0:i.trim())??"",s=((c=r.valueTo)==null?void 0:c.trim())??"",l=Nn.find(d=>d.value===r.operator);if((l==null?void 0:l.valueMode)==="single"&&!a||(l==null?void 0:l.valueMode)==="between"&&(!a||!s))return!0;switch(r.operator){case"equals":return e.toLowerCase()===a.toLowerCase();case"notEquals":return e.toLowerCase()!==a.toLowerCase();case"greaterThan":return vr(e,a)>0;case"greaterThanOrEqual":return vr(e,a)>=0;case"lessThan":return vr(e,a)<0;case"lessThanOrEqual":return vr(e,a)<=0;case"between":return vr(e,a)>=0&&vr(e,s)<=0;case"top10":case"bottom10":{const u=n.map(b=>({value:b,number:Gr(b)})).filter(b=>b.number!==null).sort((b,f)=>b.number-f.number).map(b=>b.value);return(r.operator==="top10"?u.slice(-10):u.slice(0,10)).includes(e)}case"aboveAverage":case"belowAverage":{const d=n.map(Gr).filter(b=>b!==null);if(d.length===0)return!1;const u=d.reduce((b,f)=>b+f,0)/d.length,m=Gr(e);return m===null?!1:r.operator==="aboveAverage"?m>u:m<u}default:return!0}}function rs({children:e,className:r="",style:n}){return t.jsx(nr,{onlyWhenOverflow:!0,className:r,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",width:"100%",minWidth:0,...n},children:e})}function ns({columns:e,data:r,getRowId:n,loading:a=!1,skeletonRows:s=8,emptyIcon:l,emptyText:i="Sin resultados",initialEmptyDelay:c=450,onRowClick:d,renderExpandedRow:u,getRowCanExpand:m,expandedRowIds:b,defaultExpandedRowIds:f=[],onExpandedRowIdsChange:g,expandOnRowClick:v=!1,selected:k,onToggleOne:h,onToggleAll:C,getRowSelectable:M,highlightSelected:y=!0,rowClassName:x,getRowCategory:w,stickyHeader:N=!0,pageSize:A=25,pageSizeOptions:T,pageSizeSelectWidth:U=62,pageSizeSelectHeight:K=30,pageSizeSelectPadding:Z="0 7px",totalRows:L,page:Q,onPageChange:z,onPageSizeChange:se,storageKey:re,stickyFirstColumn:R=!1,bottomOffset:V=0,compact:B=!0,restrictHeight:le=!0,maxHeight:j,minTableWidth:W,enableColumnVisibility:ae=!0,enableColumnFilters:H=!0,hiddenColumnKeys:D,defaultHiddenColumnKeys:$=Sc,onHiddenColumnKeysChange:oe,columnVisibilityLabel:G="Columnas",enableBql:X=!1,bqlValue:S,defaultBqlValue:O="",onBqlChange:I,bqlDescription:te="Filtra registros con Bonsaif Query Language",bqlPlaceholder:P=`status = activo
2
- rol IN (admin, employee)`,bqlQuickFilters:ce=[],bqlExamples:he=[],bqlSuggestions:ie=[],bqlActiveFilters:ge,bqlError:Te,onQueryChange:Le,persistState:It,onPreferencesReady:ft,enableExport:Qe=!1,exportFilename:Ot="datos"}){var ki;const Se=Mc(It,re),lt=Object.values(Se).some(Boolean),me=e.map(p=>p.key).join(","),Ye=$.join(","),qe=o.useRef(e),ct=o.useRef($);qe.current=e,ct.current=$;const[ze,bt]=o.useState(!re||!lt),mt=o.useRef(null),et=o.useRef(!re),Kt=o.useRef(!1),de=o.useRef(ft);de.current=ft;const pe=o.useRef(!re||!lt?re??"__none__":null),Me=D!==void 0,[Pe,Be]=o.useState(()=>Ut($,e)),Fe=Ut(Me?D:Pe,e),[tt,rt]=o.useState(!1),[Ke,nt]=o.useState("filter"),[Oe,Ht]=o.useState(null),[ta,ra]=o.useState(""),[at,Gt]=o.useState({}),[pt,Zt]=o.useState({}),_=b!==void 0,[J,ue]=o.useState(f),fe=S!==void 0,[$e,xe]=o.useState(O),De=fe?S:$e,[Ie,ot]=o.useState(De),[We,ht]=o.useState(!1),[zt,gt]=o.useState(!1),[lr,Wt]=o.useState(!1),[Qt,Or]=o.useState([]),Hr=o.useRef(null),ir=o.useRef(null),Bt=o.useRef(I);Bt.current=I;const na=o.useRef(A);na.current=A;const aa=o.useRef(T);aa.current=T;const gb=Array.isArray(T)?T.join(","):"",go=o.useRef(null),Kl=o.useRef(null),vo=o.useRef(null),Gl=o.useRef(0),[vb,yb]=o.useState({}),[xb,wb]=o.useState({}),[dn,oa]=o.useState(!1),yo=o.useRef(null),sa=o.useRef(null),[Nb,kb]=o.useState({}),Zl=o.useRef(null),la=o.useRef(null),[xo,Ql]=o.useState(r.length>0||a||c===!1),Jl=(p,E)=>50+(p*17+E*13+7)%40,Jt=o.useRef(null),[Sb,Cb]=o.useState(void 0),[Rl,Eb]=o.useState(0),[Mb,Tb]=o.useState(!1);o.useEffect(()=>{function p(){Tb(window.innerWidth<640)}if(!le||j!==void 0)return p(),window.addEventListener("resize",p),()=>window.removeEventListener("resize",p);const ee=A!==!1?48:0,F=12;function ne(){if(p(),!Jt.current)return;const be=Jt.current.getBoundingClientRect().top;Cb(Math.max(120,window.innerHeight-be-ee-F-V))}return ne(),window.addEventListener("resize",ne),()=>window.removeEventListener("resize",ne)},[a,A,V,le,j]);const ei=le?j??Sb:void 0;o.useEffect(()=>{const p=Jt.current;if(!p)return;const E=()=>Eb(p.clientWidth);if(E(),typeof ResizeObserver>"u")return window.addEventListener("resize",E),()=>window.removeEventListener("resize",E);const ee=new ResizeObserver(E);return ee.observe(p),()=>ee.disconnect()},[a,ze,r.length]),o.useEffect(()=>{if(c===!1||a||r.length>0){Ql(!0);return}if(xo)return;const p=window.setTimeout(()=>{Ql(!0)},c);return()=>window.clearTimeout(p)},[r.length,c,xo,a]);const[Br,Fr]=o.useState(()=>qt(e.map(p=>p.key),e)),[cr,Pr]=o.useState(()=>Object.fromEntries(e.map(p=>[p.key,yt(p,Pt(p.width))]))),[Ve,dr]=o.useState(null),[$b,ia]=o.useState(1),[ca,da]=o.useState(A===!1?0:A);o.useEffect(()=>{var Ee;const p=qe.current,E=ct.current,ee=p.map(ke=>ke.key),F=new Set(ee),ne=()=>{var ke;Kt.current||(Kt.current=!0,(ke=de.current)==null||ke.call(de))};if(!re||!lt){Se.layout&&Fr(qt(ee,p)),Me||Be(Ut(E,p)),et.current=!1,bt(!0),ne();return}let be=!1;const ye=pe.current===re;ye||(et.current=!1,bt(!1),Kt.current=!1);const Ae=kn(re);if(Jo(Ae)&&!ye){const ke=Ae,we=Zr(aa.current??Vr()),Ne=na.current,pr=Ne===!1?0:Ne,er=Se.layout?ke==null?void 0:ke.columnOrder:void 0,tr=Array.isArray(er)?er.filter(_e=>ee.includes(_e)):[],rr=ee.filter(_e=>!tr.includes(_e)),hr=qt(tr.length>0?[...tr,...rr]:ee,p),Wr=Object.fromEntries(p.map(_e=>[_e.key,yt(_e,Pt(_e.width))])),jr=Se.layout?(ke==null?void 0:ke.columnWidths)??{}:{},mn=Object.fromEntries(p.map(_e=>[_e.key,yt(_e,jr[_e.key]??Wr[_e.key])])),qr=Ut(Se.layout?(ke==null?void 0:ke.hiddenColumnKeys)??E:E,p);if(Se.layout&&(Fr(hr),Pr(mn)),Me||Be(qr),Se.filters&&(Gt(Xr(ke==null?void 0:ke.filters,F)),Zt(Kr(ke==null?void 0:ke.conditionFilters,F))),Se.sort){const _e=Yr(ke==null?void 0:ke.sort)?ke.sort:null;dr(_e&&F.has(_e.key)?_e:null)}if(Se.bql){if(Hr.current!==re){Hr.current=re;const _e=typeof(ke==null?void 0:ke.bql)=="string"?ke.bql:O;fe?(Ee=Bt.current)==null||Ee.call(Bt,_e):xe(_e)}Or(Array.isArray(ke==null?void 0:ke.bqlHistory)?ke.bqlHistory.filter(_e=>typeof _e=="string"):[])}Se.pagination&&ir.current!==re&&(ir.current=re,da(Da(ke==null?void 0:ke.pageSize,we,pr))),pe.current=re,bt(!0),ne()}const vt=`${La()??"/api/user/preferences/datatables"}?key=${encodeURIComponent(re)}`,Je=new AbortController,ve=window.setTimeout(()=>Je.abort(),2500);return fetch(vt,{cache:"no-store",signal:Je.signal}).then(ke=>ke.ok?ke.json():null).then(ke=>{var Si;if(be)return;const we=kn(re),Ne=es(Jo(ke==null?void 0:ke.settings)?ke==null?void 0:ke.settings:null,we),pr=Zr(aa.current??Vr()),er=na.current,tr=er===!1?0:er,rr=Se.layout?Ne==null?void 0:Ne.columnOrder:void 0,hr=Array.isArray(rr)?rr.filter(Ge=>ee.includes(Ge)):[],Wr=ee.filter(Ge=>!hr.includes(Ge)),jr=qt(hr.length>0?[...hr,...Wr]:ee,p),mn=Object.fromEntries(p.map(Ge=>[Ge.key,yt(Ge,Pt(Ge.width))])),qr=Se.layout?(Ne==null?void 0:Ne.columnWidths)??{}:{},_e=Object.fromEntries(p.map(Ge=>[Ge.key,yt(Ge,qr[Ge.key]??mn[Ge.key])])),Ur=Ut(Se.layout?(Ne==null?void 0:Ne.hiddenColumnKeys)??E:E,p);if(Se.layout&&(Fr(jr),Pr(_e)),Me||Be(Ur),Se.filters&&(Gt(Xr(Ne==null?void 0:Ne.filters,F)),Zt(Kr(Ne==null?void 0:Ne.conditionFilters,F))),Se.sort){const Ge=Yr(Ne==null?void 0:Ne.sort)?Ne.sort:null;dr(Ge&&F.has(Ge.key)?Ge:null)}if(Se.bql){if(Hr.current!==re){Hr.current=re;const Ge=typeof(Ne==null?void 0:Ne.bql)=="string"?Ne.bql:O;fe?(Si=Bt.current)==null||Si.call(Bt,Ge):xe(Ge)}Or(Array.isArray(Ne==null?void 0:Ne.bqlHistory)?Ne.bqlHistory.filter(Ge=>typeof Ge=="string"):[])}let je;Se.pagination&&(je=Da(Ne==null?void 0:Ne.pageSize,pr,tr),ir.current!==re&&(ir.current=re,da(je))),mt.current=JSON.stringify({columnOrder:jr,columnWidths:_e,hiddenColumnKeys:Ur,filters:Xr(Ne==null?void 0:Ne.filters,F),conditionFilters:Kr(Ne==null?void 0:Ne.conditionFilters,F),sort:Yr(Ne==null?void 0:Ne.sort)?Ne.sort:null,bql:typeof(Ne==null?void 0:Ne.bql)=="string"?Ne.bql:"",bqlHistory:Array.isArray(Ne==null?void 0:Ne.bqlHistory)?Ne.bqlHistory:[],pageSize:Se.pagination&&er!==!1?je:void 0}),et.current=!0}).catch(()=>{var ke;if(!be){const we=kn(re),Ne=Zr(aa.current??Vr()),pr=na.current,er=pr===!1?0:pr,tr=Se.layout?we==null?void 0:we.columnOrder:void 0,rr=Array.isArray(tr)?tr.filter(je=>ee.includes(je)):[],hr=ee.filter(je=>!rr.includes(je)),Wr=qt(rr.length>0?[...rr,...hr]:ee,p),jr=Object.fromEntries(p.map(je=>[je.key,yt(je,Pt(je.width))])),mn=Se.layout?(we==null?void 0:we.columnWidths)??{}:{},qr=Object.fromEntries(p.map(je=>[je.key,yt(je,mn[je.key]??jr[je.key])]));Se.layout&&(Fr(Wr),Pr(qr));const _e=Ut(Se.layout?(we==null?void 0:we.hiddenColumnKeys)??E:E,p);if(Me||Be(_e),Se.filters&&(Gt(Xr(we==null?void 0:we.filters,F)),Zt(Kr(we==null?void 0:we.conditionFilters,F))),Se.sort){const je=Yr(we==null?void 0:we.sort)?we.sort:null;dr(je&&F.has(je.key)?je:null)}if(Se.bql){if(Hr.current!==re){Hr.current=re;const je=typeof(we==null?void 0:we.bql)=="string"?we.bql:O;fe?(ke=Bt.current)==null||ke.call(Bt,je):xe(je)}Or(Array.isArray(we==null?void 0:we.bqlHistory)?we.bqlHistory.filter(je=>typeof je=="string"):[])}let Ur;Se.pagination&&(Ur=Da(we==null?void 0:we.pageSize,Ne,er),ir.current!==re&&(ir.current=re,da(Ur))),mt.current=JSON.stringify({columnOrder:Wr,columnWidths:qr,hiddenColumnKeys:_e,filters:Xr(we==null?void 0:we.filters,F),conditionFilters:Kr(we==null?void 0:we.conditionFilters,F),sort:Yr(we==null?void 0:we.sort)?we.sort:null,bql:typeof(we==null?void 0:we.bql)=="string"?we.bql:"",bqlHistory:Array.isArray(we==null?void 0:we.bqlHistory)?we.bqlHistory:[],pageSize:Se.pagination&&pr!==!1?Ur:void 0}),et.current=!0}}).finally(()=>{window.clearTimeout(ve),be||(pe.current=re,bt(!0),ne())}),()=>{be=!0,Je.abort(),window.clearTimeout(ve)}},[re,lt,me,Ye,Me,Se.layout,Se.filters,Se.sort,Se.bql,Se.pagination,fe,O,gb]),o.useEffect(()=>{if(!re||!ze||!lt||!et.current)return;const p={};Se.layout&&(p.columnOrder=Br,p.columnWidths=cr,p.hiddenColumnKeys=Fe),Se.filters&&(p.filters=at,p.conditionFilters=pt),Se.sort&&(p.sort=Ve),Se.bql&&(p.bql=De,p.bqlHistory=Qt),Se.pagination&&A!==!1&&(p.pageSize=ca);const E=kn(re),ee=es(E,p),F=JSON.stringify(ee);if(F===mt.current)return;Ec(re,ee),mt.current=F;const ne=window.setTimeout(()=>{const be=La()??"/api/user/preferences/datatables";fetch(be,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:re,settings:ee})}).then(()=>{}).catch(()=>{})},300);return()=>window.clearTimeout(ne)},[Br,cr,Fe,at,pt,Ve,De,Qt,ca,A,re,ze,lt,Se.layout,Se.filters,Se.sort,Se.bql,Se.pagination]),o.useEffect(()=>{Fr(p=>{const E=e.map(ne=>ne.key),ee=p.filter(ne=>E.includes(ne)),F=E.filter(ne=>!ee.includes(ne));return qt([...ee,...F],e)})},[me,e]);const ti=qt(Br,e).map(p=>e.find(E=>E.key===p)).filter(p=>!!p),Ct=ti.filter(p=>!Fe.includes(p.key)),ri=e.some(Ia),Ab=Object.keys(at).length,Lb=Object.keys(pt).length,wo=Ab+Lb;function ni(p){const E=new Set;return r.reduce((ee,F)=>{const ne=Sn(p,F);return!ne||E.has(ne)||(E.add(ne),ee.push({value:ne,label:ne})),ee},[])}function Db(){const p=e.find(E=>E.key===Oe);return p?ni(p):[]}function Ib(p){return!!(H&&!or(p)&&(p.filterValue||p.sortKey||ni(p).length>0))}function ai(p,E){Gt(ee=>{const F={...ee};return F[p]=E,F})}function Ob(p,E,ee,F){const ne=at[p]??[],be=F?ne:ee.filter(Ae=>Ae!==E),ye=F?ne.includes(E)?ne.filter(Ae=>Ae!==E):[...ne,E]:be;ye.length===ee.length?No(p):ai(p,ye)}function No(p){Gt(E=>{const ee={...E};return delete ee[p],ee})}function ua(p,E){Zt(ee=>{const F={...ee};return E?F[p]=E:delete F[p],F})}function oi(p){ua(p,null)}function Hb(){Gt({}),Zt({})}function Bb(p){fe||xe(p),I==null||I(p)}function si(p){const E=p.trim();ot(E),(I==null?void 0:I(E))!==!1&&(fe||xe(E),ht(!1),gt(!1),Wt(!1),E&&Or(F=>[E,...F.filter(ne=>ne!==E)].slice(0,xc)))}function li(){ot(""),Bb(""),ht(!1),gt(!1),Wt(!1)}function ko(p,E){ot(p),E&&(E.style.height="auto",E.style.height=`${Math.min(E.scrollHeight,180)}px`)}function fa(p){const E=p.trim();if(!E)return;Gl.current=Date.now()+500;const ee=Ie.replace(/\s+$/u,""),F=ee.length===0?E:ee.split(`
3
- `).map(ne=>ne.trim()).includes(E)?ee:`${ee}
4
- ${E}`;ko(F,vo.current??void 0),requestAnimationFrame(()=>{const ne=vo.current;if(!ne)return;ne.focus();const be=ne.value.length;ne.setSelectionRange(be,be),ko(ne.value,ne)})}o.useEffect(()=>{ot(De)},[De]);const ba=o.useCallback(()=>{const p=go.current;if(!p)return;const E=p.getBoundingClientRect(),ee=12,F=8,ne=Math.min(780,Math.max(320,window.innerWidth-32)),be=Math.max(ee,window.innerWidth-ne-ee),ye=Math.min(Math.max(ee,E.left),be),Ae=E.bottom+F,Re=window.innerHeight-E.top+F,Xe=window.innerHeight-Ae-ee,vt=E.top-ee-F,Je=Xe<280&&vt>Xe,ve=Math.max(240,Je?vt:Xe);yb({position:"fixed",zIndex:1e4,left:ye,top:Je?void 0:Ae,bottom:Je?Re:void 0,width:ne,maxWidth:"calc(100vw - 24px)",maxHeight:ve,overflowY:"auto"})},[]);o.useEffect(()=>{if(!We)return;function p(F){var be,ye;if(Date.now()<Gl.current)return;const ne=F.target;(be=go.current)!=null&&be.contains(ne)||(ye=Kl.current)!=null&&ye.contains(ne)||(ht(!1),gt(!1),Wt(!1))}function E(F){F.key==="Escape"&&(ht(!1),gt(!1),Wt(!1))}function ee(){ba()}return ba(),document.addEventListener("mousedown",p),window.addEventListener("keydown",E),window.addEventListener("resize",ee),window.addEventListener("scroll",ee,!0),()=>{document.removeEventListener("mousedown",p),window.removeEventListener("keydown",E),window.removeEventListener("resize",ee),window.removeEventListener("scroll",ee,!0)}},[We,ba]);function ii(p){const E=Ut(p,e);Me||Be(E),oe==null||oe(E)}function Fb(p){ii(Fe.includes(p)?Fe.filter(E=>E!==p):[...Fe,p])}function Pb(){ii([])}const So=o.useCallback((p=la.current)=>{if(!p)return;const E=p.getBoundingClientRect(),ee=Math.min(292,Math.max(240,window.innerWidth-16)),F=Math.max(8,window.innerWidth-ee-8),ne=Math.min(Math.max(8,E.right-ee),F),be=window.innerHeight-E.bottom,ye=E.bottom+6,Ae=window.innerHeight-E.top+6,Xe=be<360&&E.top>be?void 0:ye,vt=Xe===void 0?Ae:void 0,Je=Math.max(220,Xe===void 0?E.top-16:window.innerHeight-ye-8),ve={position:"fixed",zIndex:9999,left:ne,top:Xe,bottom:vt,width:ee,maxWidth:"calc(100vw - 16px)",maxHeight:Je,"--dt-column-menu-max-height":`${Je}px`};wb(ve)},[]);function ci(p,E,ee=null){p.preventDefault(),p.stopPropagation();const F=la.current===p.currentTarget&&Ke===E&&Oe===ee;if(tt&&F){rt(!1),Ht(null);return}la.current=p.currentTarget,nt(E),Ht(ee),ra(""),So(p.currentTarget),rt(!0)}function _b(p){if(or(p))return;const E=Jt.current;if(!E)return;const F=Array.from(E.querySelectorAll("[data-dt-column-key]")).filter(ne=>ne.dataset.dtColumnKey===p.key).reduce((ne,be)=>{const ye=be.querySelector("[data-dt-autofit-content]"),Ae=ye?ye.scrollWidth:Math.max(be.scrollWidth,be.offsetWidth);return Math.max(ne,Math.ceil(Ae+Tc(be)))},0);F<=0||Pr(ne=>({...ne,[p.key]:yt(p,F+12)}))}o.useEffect(()=>{Pr(p=>{const E=Object.fromEntries(e.map(ee=>[ee.key,yt(ee,Pt(ee.width))]));return Object.fromEntries(e.map(ee=>[ee.key,yt(ee,p[ee.key]??E[ee.key])]))})},[me,e]),o.useEffect(()=>{Me||Be(p=>Ut(p,e))},[me,e,Me]),o.useEffect(()=>{function p(F){var ye,Ae;const ne=F.target,be=F.target;be!=null&&be.closest("[data-bonsaif-select-dropdown='true']")||!((ye=Zl.current)!=null&&ye.contains(ne))&&!((Ae=la.current)!=null&&Ae.contains(ne))&&(rt(!1),Ht(null))}function E(F){F.key==="Escape"&&(rt(!1),Ht(null))}function ee(){So()}return tt&&(document.addEventListener("mousedown",p),window.addEventListener("keydown",E),window.addEventListener("resize",ee),window.addEventListener("scroll",ee,!0)),()=>{document.removeEventListener("mousedown",p),window.removeEventListener("keydown",E),window.removeEventListener("resize",ee),window.removeEventListener("scroll",ee,!0)}},[tt,So]);const un=o.useRef(null);o.useEffect(()=>{function p(ee){const F=un.current;if(!F)return;const ne=ee.clientX-F.startX,be=e.find(ye=>ye.key===F.colKey);be&&Pr(ye=>({...ye,[F.colKey]:yt(be,F.startWidth+ne)}))}function E(){un.current&&(un.current=null,document.body.style.cursor="",document.body.style.userSelect="")}return document.addEventListener("pointermove",p),document.addEventListener("pointerup",E),()=>{document.removeEventListener("pointermove",p),document.removeEventListener("pointerup",E)}},[e]);const fn=o.useRef(null),[di,Co]=o.useState(null);function zb(p,E){const ee=e.find(F=>F.key===p);if(!ee||!ts(ee)){E.preventDefault();return}fn.current=Br.indexOf(p),E.dataTransfer.effectAllowed="move"}function Wb(p,E){E.preventDefault(),E.dataTransfer.dropEffect="move";const ee=Br.indexOf(p);di!==ee&&Co(ee)}function jb(p,E){E.preventDefault();const ee=fn.current,F=Br.indexOf(p);ee!==null&&ee!==F&&Fr(ne=>{const be=[...ne],[ye]=be.splice(ee,1);return be.splice(F,0,ye),qt(be,e)}),fn.current=null,Co(null)}function qb(){fn.current=null,Co(null)}function Ub(p){p.sortKey&&dr(E=>(E==null?void 0:E.key)===p.key?{key:p.key,dir:E.dir==="asc"?"desc":"asc"}:{key:p.key,dir:"asc"})}o.useEffect(()=>{ia(1)},[r]),o.useEffect(()=>{ia(1)},[pt,at]);const ur=!!(z&&se),Rt=A!==!1,Eo=o.useMemo(()=>Zr(T??Vr()),[T]),it=ur?Q??1:$b,ui=Rt&&ca<1?typeof A=="number"&&A>0?A:Eo[0]??25:ca,Ft=ur||Rt?ui:r.length,Tt=!!k&&!!h&&!!C,Mo=o.useMemo(()=>M?r.filter(p=>M(p)):r,[r,M]),_r=!!u,fi=o.useMemo(()=>new Set(_?Array.from(b??[]):J),[_,b,J]),Vb=(_r?40:0)+(Tt?40:0),To=!Mb&&(ri||R),ma=(()=>{if(!To)return{};let p=Vb;const E={};return Ct.forEach((ee,F)=>{(Ia(ee)||!ri&&R&&F===0)&&(E[ee.key]=p,p+=cr[ee.key]??yt(ee,Pt(ee.width)))}),E})(),$o=Object.keys(ma),Ao=$o.length>0?$o[$o.length-1]:null,bi=Tt&&Mo.length>0&&Mo.every(p=>k.has(n(p))),Yb=Tt&&k.size>0&&Mo.some(p=>k.has(n(p)))&&!bi,pa=o.useMemo(()=>{const p=Object.entries(at),E=Object.entries(pt);return p.length===0&&E.length===0?r:r.filter(ee=>p.every(([F,ne])=>{const be=e.find(ye=>ye.key===F);return be?ne.includes(Sn(be,ee)):!0})&&E.every(([F,ne])=>{const be=e.find(Ae=>Ae.key===F);if(!be)return!0;const ye=r.map(Ae=>Sn(be,Ae));return Lc(Sn(be,ee),ne,ye)}))},[pt,at,e,r]),fr=o.useMemo(()=>{if(!Ve)return pa;const p=e.find(E=>E.key===Ve.key&&E.sortKey);return p!=null&&p.sortKey?[...pa].sort((E,ee)=>{const F=E[p.sortKey],ne=ee[p.sortKey],be=F===ne?0:F==null?1:ne==null||F<ne?-1:1;return Ve.dir==="asc"?be:-be}):pa},[pa,Ve,e]),mi=o.useMemo(()=>{if(ur||!Rt)return fr;const p=(it-1)*Ft;return fr.slice(p,p+Ft)},[fr,ur,Rt,it,Ft]),br=ur?L??r.length:fr.length,Lo=Rt?Math.max(1,Math.ceil(br/Ft)):1,Xb=Math.min(...Eo),Kb=Rt&&(br>Ft||br>Xb),Gb=Rt?(it-1)*Ft+1:1,Zb=Rt?Math.min(it*Ft,br):br;function Do(p){if(a)return;const E=Math.max(1,Math.min(p,Lo));ur?z(E):ia(E)}function Qb(p){a||(re&&(ir.current=re),da(p),ur?(se(p),z(1)):(ia(1),se==null||se(p)))}function pi(p){const E=new Set(fi);E.has(p)?E.delete(p):E.add(p);const ee=Array.from(E);_||ue(ee),g==null||g(ee)}o.useEffect(()=>{Le==null||Le({bql:De,filters:at,conditionFilters:pt,sort:Ve,page:it,pageSize:Ft,hiddenColumnKeys:Fe})},[De,at,pt,Ve,it,Ft,Fe,Le]);const hi=p=>p==="center"?"justify-center text-center":p==="right"?"justify-end text-right":"justify-start text-left",Jb="color-mix(in srgb, var(--primary) 6%, var(--bg-card))",Io="linear-gradient(180deg, color-mix(in srgb, var(--bg-input) 90%, var(--bg-card)) 0%, color-mix(in srgb, var(--bg-input) 70%, var(--bg-card)) 100%)",He="color-mix(in srgb, var(--border) 62%, var(--bg-card))",mr="color-mix(in srgb, var(--primary) 24%, var(--border))",ha=`inset 0 0 0 1px ${He}`,gi=Ct.reduce((p,E)=>p+(cr[E.key]??Pt(E.width)),(_r?40:0)+(Tt?40:0)),vi=typeof W=="number"?W:typeof W=="string"?Number(((ki=W.match(/^(\d+(?:\.\d+)?)px$/))==null?void 0:ki[1])??NaN):NaN,bn=Number.isFinite(vi)?Math.max(gi,vi,Rl):Math.max(gi,Rl),ga=W??bn,zr=`${_r?"40px ":""}${Tt?"40px ":""}${Ct.map(p=>`${cr[p.key]??Pt(p.width)}px`).join(" ")}`;o.useEffect(()=>{Ve&&Fe.includes(Ve.key)&&dr(null)},[Fe,Ve]);function yi(p){return p?typeof p=="string"?{key:p,label:p}:p:null}const va=()=>t.jsxs("div",{role:"row",className:"grid",style:{gridTemplateColumns:zr,background:Io,borderBottom:`1px solid ${mr}`},children:[_r&&t.jsx("div",{role:"columnheader",className:`${B?"px-2 py-1.5":"px-3 py-2.5"} w-10`,style:{borderBottom:`1px solid ${mr}`,borderRight:`1px solid ${He}`}}),Tt&&t.jsx("div",{role:"columnheader",className:`${B?"px-2 py-1.5":"px-3 py-2.5"} flex w-10 items-center justify-center`,style:To?{position:"sticky",left:0,zIndex:12,background:Io,backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)",boxShadow:`inset 0 -1px 0 ${mr}`,borderRight:`1px solid ${He}`}:{borderBottom:`1px solid ${mr}`,borderRight:`1px solid ${He}`},children:t.jsx(vn,{size:"sm",checked:bi,indeterminate:Yb,onChange:C,"aria-label":"Seleccionar todos",containerClassName:"items-center",className:"cursor-pointer"})}),Ct.map((p,E)=>{const ee=(Ve==null?void 0:Ve.key)===p.key,F=!!p.sortKey,ne=or(p),be=ma[p.key],ye=be!==void 0,Ae=p.key===Ao,Re=ts(p),Xe=di===E,Je=(cr[p.key]??Pt(p.width))<120,ve=Object.prototype.hasOwnProperty.call(at,p.key)||Object.prototype.hasOwnProperty.call(pt,p.key);return t.jsxs("div",{role:"columnheader","data-dt-column-key":p.key,className:`group select-none ${Je?"text-left":hi(p.align)}`,style:{...ye?{position:"sticky",left:be,zIndex:12,background:Io,backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)",boxShadow:Ae?`3px 0 6px -2px rgba(0,0,0,0.10), inset 0 -1px 0 ${mr}`:`inset 0 -1px 0 ${mr}`,borderRight:`1px solid ${He}`}:{position:"relative",borderBottom:`1px solid ${mr}`,borderRight:`1px solid ${He}`},color:ee?"var(--primary)":"var(--text-muted)",whiteSpace:"nowrap",transition:"color 0.15s",borderLeft:Xe?"2px solid var(--primary)":"2px solid transparent",cursor:"default",padding:ne?B?"7px 6px":"9px 8px":B?"8px 6px 10px":"10px 8px 12px"},onDragOver:Ee=>{(Re||fn.current!==null)&&Wb(p.key,Ee)},onDrop:Ee=>jb(p.key,Ee),children:[t.jsxs("div",{className:`flex min-w-0 items-center gap-1 ${ne?"justify-center":Je?"justify-start":p.align==="center"?"justify-center":p.align==="right"?"justify-end":"justify-start"}`,children:[Re?t.jsx("span",{draggable:!0,onDragStart:Ee=>{Ee.stopPropagation(),zb(p.key,Ee)},onDragEnd:Ee=>{Ee.stopPropagation(),qb()},onClick:Ee=>Ee.stopPropagation(),title:"Arrastrar para mover columna","aria-label":"Arrastrar para mover columna",className:`absolute left-0 top-0 z-10 inline-flex h-full w-3 shrink-0 rounded-sm transition-colors duration-150 hover:bg-[var(--primary)]/15 ${Xe?"bg-[var(--primary)]/20":""}`,style:{cursor:"grab"}}):null,ne?t.jsx("span",{className:"inline-flex h-5 w-5 items-center justify-center rounded-md text-[var(--text-muted)]",title:"Acciones","aria-label":"Acciones",children:t.jsx(q.HiCog6Tooth,{className:"h-3.5 w-3.5"})}):t.jsx(rs,{className:"min-w-0 flex-1",children:t.jsx("span",{"data-dt-autofit-content":!0,className:`inline-flex max-w-full items-center font-semibold uppercase tracking-wider ${B?"text-[11px]":"text-xs"}`,children:t.jsx("span",{className:"min-w-0 truncate",children:p.header})})}),F&&t.jsx("button",{type:"button","aria-label":`Ordenar por ${String(p.header)}`,title:"Ordenar",onClick:Ee=>{Ee.stopPropagation(),Ub(p)},"data-dt-sort-button":!0,className:`absolute -bottom-2 left-1/2 z-20 inline-flex h-4 w-4 -translate-x-1/2 items-center justify-center rounded-full bg-[var(--primary)] text-[var(--primary-fg)] shadow-[0_1px_3px_rgba(15,23,42,0.22)] transition-[opacity,transform] duration-150 hover:scale-105 focus:scale-105 focus:opacity-100 focus:outline-none ${ee?"opacity-100":"opacity-0 group-hover:opacity-100 group-focus-within:opacity-100"}`,style:{bottom:"-0.5rem",top:"auto"},children:ee?Ve.dir==="asc"?t.jsx(q.HiChevronUp,{className:"h-3 w-3"}):t.jsx(q.HiChevronDown,{className:"h-3 w-3"}):t.jsx(q.HiChevronUpDown,{className:"h-3 w-3"})}),H&&!ne&&Ib(p)&&t.jsx("button",{type:"button","aria-haspopup":"menu","aria-expanded":tt&&Oe===p.key,"aria-label":`Filtrar ${String(p.header)}`,title:"Filtrar",onClick:Ee=>ci(Ee,"filter",p.key),className:`inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-sm bg-transparent text-[var(--text-muted)] opacity-0 transition-[opacity,color,background-color] duration-150 hover:bg-[var(--bg-card)] hover:text-[var(--primary)] focus:bg-[var(--bg-card)] focus:text-[var(--primary)] focus:opacity-100 group-hover:opacity-100 ${tt&&Ke==="filter"&&Oe===p.key?"bg-[var(--bg-card)] text-[var(--primary)] opacity-100":ve?"text-[var(--primary)] opacity-100":""}`,children:ve?t.jsx(q.HiFunnel,{className:"h-3.5 w-3.5"}):t.jsx(q.HiEllipsisVertical,{className:"h-3.5 w-3.5"})})]}),!ne&&t.jsx("span",{role:"separator","aria-orientation":"vertical",title:"Arrastrar para redimensionar. Doble click para autoajustar",onPointerDown:Ee=>{Ee.preventDefault(),Ee.stopPropagation(),un.current={colKey:p.key,startX:Ee.clientX,startWidth:cr[p.key]??150},document.body.style.cursor="col-resize",document.body.style.userSelect="none"},onDoubleClick:Ee=>{Ee.preventDefault(),Ee.stopPropagation(),un.current=null,document.body.style.cursor="",document.body.style.userSelect="",_b(p)},onClick:Ee=>Ee.stopPropagation(),className:"absolute top-0 flex h-full items-center justify-center opacity-0 transition-opacity duration-200 hover:opacity-100",style:{right:0,width:12,cursor:"col-resize",zIndex:6,transform:"translateX(50%)"},children:t.jsxs("span",{style:{display:"flex",gap:4,alignItems:"center",height:"calc(100% - 8px)"},children:[t.jsx("span",{style:{width:2,height:"100%",borderRadius:2,background:"var(--primary)",display:"block"}}),t.jsx("span",{style:{width:2,height:"100%",borderRadius:2,background:"var(--primary)",display:"block"}})]})})]},p.key)})]}),ya=()=>{if(!tt||typeof document>"u"||Ke==="visibility"&&!ae||Ke==="filter"&&!H)return null;const p=e.find(ve=>ve.key===Oe),E=Db(),ee=p?Object.prototype.hasOwnProperty.call(at,p.key):!1,F=p?pt[p.key]:void 0,ne=Nn.find(ve=>ve.value===(F==null?void 0:F.operator)),be=p?at[p.key]??[]:[],ye=ta.trim().toLowerCase(),Ae=ye?E.filter(ve=>ve.label.toLowerCase().includes(ye)):E,Re=p&&E.length>0&&(!ee||be.length===E.length),Xe=p&&ee&&be.length>0&&be.length<E.length,vt=Fe.length,Je=()=>{p&&(No(p.key),oi(p.key))};return dt.createPortal(t.jsx("div",{ref:Zl,role:"menu",className:"overflow-hidden rounded-lg border p-1 shadow-xl",style:{...xb,borderColor:"var(--border)",background:"var(--bg-card)"},children:Ke==="visibility"?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-[var(--border)] px-2 py-1.5",children:[t.jsx("span",{className:"min-w-0 truncate text-xs font-semibold uppercase text-[var(--text-muted)]",children:vt>0?`${Ct.length} de ${e.length} visibles`:`${e.length} visibles`}),t.jsx("button",{type:"button",onClick:Pb,disabled:vt===0,className:"rounded px-1.5 py-0.5 text-xs font-medium text-[var(--primary)] transition-colors hover:bg-[var(--bg-input)] disabled:opacity-40",children:"Mostrar todas"})]}),t.jsx("div",{className:"max-h-72 overflow-auto py-1",children:ti.map(ve=>{const Ee=!Fe.includes(ve.key),we=!(ve.hideable!==!1)||Ee&&Ct.length<=1;return t.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":Ee,disabled:we,onClick:()=>Fb(ve.key),className:"flex w-full min-w-0 items-center gap-2 rounded-md px-2.5 py-1.5 text-left transition-colors hover:bg-[var(--bg-input)] disabled:cursor-not-allowed disabled:opacity-50",style:{color:"var(--text-main)"},children:[t.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center rounded border",style:{borderColor:Ee?"var(--primary)":"var(--border)",background:Ee?"var(--primary)":"var(--bg-input)",color:"var(--primary-fg)"},children:Ee&&t.jsx(q.HiCheck,{className:"h-3 w-3"})}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:ve.header})]},ve.key)})})]}):p?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-[var(--border)] px-2 py-1.5",children:[t.jsxs("span",{className:"min-w-0 truncate text-xs font-semibold uppercase text-[var(--text-muted)]",children:["Filtrar ",p.header]}),t.jsx("button",{type:"button",onClick:Je,disabled:!ee&&!F,className:"rounded px-1.5 py-0.5 text-xs font-medium text-[var(--primary)] transition-colors hover:bg-[var(--bg-input)] disabled:opacity-40",children:"Limpiar"})]}),p.sortKey&&t.jsxs("div",{className:"grid grid-cols-2 gap-1 border-b border-[var(--border)] p-1",children:[t.jsxs("button",{type:"button",onClick:()=>dr({key:p.key,dir:"asc"}),className:"flex min-w-0 items-center justify-between rounded-md px-2 py-1.5 text-left text-sm transition-colors hover:bg-[var(--bg-input)]",style:{color:"var(--text-main)"},children:[t.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 truncate",children:[t.jsx(q.HiChevronUp,{className:"h-4 w-4 shrink-0 text-[var(--primary)]"}),t.jsx("span",{className:"truncate",children:"Ascendente"})]}),(Ve==null?void 0:Ve.key)===p.key&&Ve.dir==="asc"&&t.jsx(q.HiCheck,{className:"h-4 w-4 shrink-0 text-[var(--primary)]"})]}),t.jsxs("button",{type:"button",onClick:()=>dr({key:p.key,dir:"desc"}),className:"flex min-w-0 items-center justify-between rounded-md px-2 py-1.5 text-left text-sm transition-colors hover:bg-[var(--bg-input)]",style:{color:"var(--text-main)"},children:[t.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 truncate",children:[t.jsx(q.HiChevronDown,{className:"h-4 w-4 shrink-0 text-[var(--primary)]"}),t.jsx("span",{className:"truncate",children:"Descendente"})]}),(Ve==null?void 0:Ve.key)===p.key&&Ve.dir==="desc"&&t.jsx(q.HiCheck,{className:"h-4 w-4 shrink-0 text-[var(--primary)]"})]})]}),t.jsxs("div",{className:"border-b border-[var(--border)] p-2",children:[t.jsxs("div",{className:"grid grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)] gap-2",children:[t.jsx(ar,{value:(F==null?void 0:F.operator)??"",onChange:ve=>{if(!ve){oi(p.key);return}ua(p.key,{operator:ve,value:(F==null?void 0:F.value)??"",valueTo:(F==null?void 0:F.valueTo)??""})},options:yc,placeholder:"Opcion",emptyLabel:"Sin condicion",ariaLabel:"Operador de filtro",searchable:!1,height:34,padding:"0 9px",dropdownMinWidth:260,className:"min-w-0 [&>button]:rounded-md [&>button]:text-sm [&>button]:font-medium"}),(ne==null?void 0:ne.valueMode)!=="none"?t.jsx("input",{value:(F==null?void 0:F.value)??"",onChange:ve=>{F&&ua(p.key,{...F,value:ve.target.value})},disabled:!F,placeholder:"Valor",className:"min-w-0 rounded-md border px-2 py-1.5 text-sm outline-none transition-colors placeholder:text-[var(--text-muted)] focus:border-[var(--primary)] disabled:opacity-50",style:{borderColor:"var(--border)",background:"var(--bg-input)",color:"var(--text-main)"}}):t.jsx("div",{className:"min-h-8 rounded-md border px-2 py-1.5 text-sm text-[var(--text-muted)]",style:{borderColor:"var(--border)",background:"var(--bg-input)"},children:"Automatico"})]}),(ne==null?void 0:ne.valueMode)==="between"&&t.jsx("input",{value:(F==null?void 0:F.valueTo)??"",onChange:ve=>{F&&ua(p.key,{...F,valueTo:ve.target.value})},placeholder:"Valor final",className:"mt-2 w-full rounded-md border px-2 py-1.5 text-xs outline-none transition-colors placeholder:text-[var(--text-muted)] focus:border-[var(--primary)]",style:{borderColor:"var(--border)",background:"var(--bg-input)",color:"var(--text-main)"}})]}),t.jsx("div",{className:"border-b border-[var(--border)] p-2",children:t.jsxs("div",{className:"flex items-center gap-1 rounded-md border px-2 py-1.5 text-sm",style:{borderColor:"var(--border)",background:"var(--bg-input)"},children:[t.jsx(q.HiMagnifyingGlass,{className:"h-4 w-4 shrink-0 text-[var(--text-muted)]"}),t.jsx("input",{value:ta,onChange:ve=>ra(ve.target.value),placeholder:"Buscar",className:"min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-[var(--text-muted)]",style:{color:"var(--text-main)"}})]})}),t.jsxs("div",{className:"overflow-auto py-1",style:{maxHeight:"max(96px, calc(var(--dt-column-menu-max-height, 520px) - 236px))"},children:[t.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":Xe?"mixed":!!Re,onClick:()=>{p&&(Re&&!ee?ai(p.key,[]):No(p.key))},className:"flex w-full min-w-0 items-center gap-2 rounded-md px-2.5 py-1.5 text-left transition-colors hover:bg-[var(--bg-input)]",style:{color:"var(--text-main)"},children:[t.jsxs("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center rounded border",style:{borderColor:Re||Xe?"var(--primary)":"var(--border)",background:Re||Xe?"var(--primary)":"var(--bg-input)",color:"var(--primary-fg)"},children:[Xe&&t.jsx(q.HiMinus,{className:"h-3 w-3"}),Re&&!Xe&&t.jsx(q.HiCheck,{className:"h-3 w-3"})]}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:"Seleccionar todo"})]}),Ae.map(ve=>{const Ee=!ee||be.includes(ve.value);return t.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":Ee,onClick:()=>Ob(p.key,ve.value,E.map(ke=>ke.value),ee),className:"flex w-full min-w-0 items-center gap-2 rounded-md px-2.5 py-1.5 text-left transition-colors hover:bg-[var(--bg-input)]",style:{color:"var(--text-main)"},children:[t.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center rounded border",style:{borderColor:Ee?"var(--primary)":"var(--border)",background:Ee?"var(--primary)":"var(--bg-input)",color:"var(--primary-fg)"},children:Ee&&t.jsx(q.HiCheck,{className:"h-3 w-3"})}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:ve.label})]},ve.value)}),Ae.length===0&&t.jsx("div",{className:"px-3 py-3 text-sm text-[var(--text-muted)]",children:"Sin valores"})]})]}):null}),document.body)};o.useEffect(()=>{if(!dn)return;function p(E){yo.current&&!yo.current.contains(E.target)&&sa.current&&!sa.current.contains(E.target)&&oa(!1)}return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[dn]);function xi(p,E){if(p.filterValue){const ee=p.filterValue(E);return ee==null||ee===""?"":String(ee)}return gr(p.cell(E))}function wi(p){return`"${p.replace(/"/g,'""')}"`}function xa(p){return p.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function Rb(){const p=Ct.filter(Ae=>!or(Ae)),E=p.map(Ae=>wi(gr(Ae.header))).join(","),ee=fr.map(Ae=>p.map(Re=>wi(xi(Re,Ae))).join(",")).join(`
5
- `),F=`${E}
6
- ${ee}`,ne=new Blob(["\uFEFF"+F],{type:"text/csv;charset=utf-8;"}),be=URL.createObjectURL(ne),ye=document.createElement("a");ye.href=be,ye.download=`${Ot}.csv`,document.body.appendChild(ye),ye.click(),document.body.removeChild(ye),URL.revokeObjectURL(be)}function em(){const p=Ct.filter(ye=>!or(ye)),E=p.map(ye=>xa(gr(ye.header))),F=fr.map(ye=>p.map(Ae=>xa(xi(Ae,ye)))).map(ye=>`<tr>${ye.map(Ae=>`<td>${Ae}</td>`).join("")}</tr>`).join(""),ne=`<!DOCTYPE html>
7
- <html lang="es"><head><meta charset="utf-8"><title>${xa(Ot)}</title>
1
+ (function(V,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("react"),require("react/jsx-runtime"),require("react-icons/hi2"),require("react-dom"),require("recharts"),require("overlayscrollbars"),require("sonner"),require("overlayscrollbars-react"),require("react-day-picker"),require("react-day-picker/dist/style.css"),require("react-icons/fi")):typeof define=="function"&&define.amd?define(["exports","react","react/jsx-runtime","react-icons/hi2","react-dom","recharts","overlayscrollbars","sonner","overlayscrollbars-react","react-day-picker","react-day-picker/dist/style.css","react-icons/fi"],o):(V=typeof globalThis<"u"?globalThis:V||self,o(V.BonsaifUI={},V.React,V.jsxRuntime,V.ReactIconsHi2,V.ReactDOM,V.Recharts,V.OverlayScrollbarsGlobal,V.Sonner,V.OverlayScrollbarsReact,V.ReactDayPicker,V.ReactDayPickerStyles,V.ReactIconsFi))})(this,(function(V,o,t,q,ct,Se,Ea,Ma,zo,Ta,cm,Li){"use strict";"use client";function Vt(...e){return e.filter(Boolean).join(" ")}function Di({variant:e="primary",className:r,type:n="button",children:a,...s}){return t.jsx("button",{className:Vt("bonsaif-ui-button",`bonsaif-ui-button--${e}`,r),type:n,...s,children:a})}function Wo({value:e,onChange:r,placeholder:n,className:a="",autoFocus:s=!1,forceExpanded:l=!1,onEscape:i,size:c="default",inputTabIndex:d}){const u=o.useRef(null),[m,b]=o.useState(!1),f=l||m||e.trim().length>0,g=c==="sm"?"h-9 rounded-md":"h-10 rounded-lg",v=a||"w-48 max-w-full sm:w-64 lg:w-72";o.useEffect(()=>{var h;s&&((h=u.current)==null||h.focus())},[s]);const k=()=>{var h;b(!0),(h=u.current)==null||h.focus()};return t.jsxs("div",{className:`relative min-w-0 max-w-full flex-shrink-0 overflow-visible transition-[width] duration-200 ease-out ${f?v:"w-24 sm:w-28"}`,onMouseDown:h=>{f||(h.preventDefault(),k())},children:[t.jsx(q.HiMagnifyingGlass,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 pointer-events-none transition-colors duration-200",style:{color:"var(--text-muted)",left:"var(--page-header-control-icon-left, 12px)"}}),t.jsx("input",{ref:u,type:"text",tabIndex:d,"aria-label":n,value:e,onChange:h=>r(h.target.value),onKeyDown:h=>{h.key==="Escape"&&(i==null||i())},placeholder:f?n:"Buscar",className:`${g} w-full py-0 text-sm leading-none placeholder:text-[var(--text-muted)] focus:outline-none transition-all duration-200 ${f?"pl-9 pr-8":"cursor-pointer pl-9 pr-3"}`,style:{height:`var(--page-header-control-height, ${c==="sm"?"36px":"40px"})`,paddingLeft:"calc(var(--page-header-control-icon-left, 12px) + 24px)",paddingRight:f?"calc(var(--page-header-control-padding-x, 14px) + 18px)":"var(--page-header-control-padding-x, 14px)",background:"color-mix(in srgb, var(--bg-card) 86%, transparent)",border:"1px solid var(--border)",color:"var(--text-main)"},onFocus:h=>{b(!0),h.currentTarget.style.borderColor="var(--primary)",h.currentTarget.style.boxShadow="0 0 0 3px rgba(59,130,246,0.12)"},onBlur:h=>{b(!1),h.currentTarget.style.borderColor="var(--border)",h.currentTarget.style.boxShadow="none"}}),e&&t.jsx("button",{type:"button",onClick:()=>r(""),className:"absolute right-2 top-1/2 flex !h-6 !w-6 -translate-y-1/2 items-center justify-center rounded-full !p-0 leading-none transition-colors hover:bg-black/5",style:{color:"var(--text-muted)",right:"var(--page-header-control-padding-x, 8px)"},"aria-label":"Limpiar búsqueda",children:t.jsx(q.HiXMark,{className:"h-3.5 w-3.5 flex-shrink-0"})})]})}const jo=o.createContext({});let qo=0;const Uo="bonsaif-ui:hide-tooltips";function yn(e=700){qo=Date.now()+e}function Ii(){return Date.now()>qo}function xn(e){if(typeof document>"u")return!1;const r=Array.from(document.querySelectorAll('[data-bonsaif-overlay="true"], [role="menu"], [role="dialog"][aria-modal="true"], [aria-hidden="false"] [aria-modal="true"]'));return e&&r.some(n=>n.contains(e))?!1:r.length>0}function Oi(e){var a;const r=Array.from(e.querySelectorAll("*")).filter(s=>{var l;return s.scrollWidth>s.clientWidth&&!!((l=s.textContent)!=null&&l.trim())&&s.tagName.toLowerCase()!=="svg"&&!s.closest("svg")});return(e.scrollWidth>e.clientWidth||r.length>0)&&(((a=r[0])==null?void 0:a.textContent)??e.textContent??"").trim()||null}function Yt({children:e,content:r,onlyWhenOverflow:n=!1,interactive:a=!1,followCursor:s=!0,placement:l="bottom",showArrow:i=!1,className:c="",tooltipClassName:d="",style:u,tooltipStyle:m,as:b="div"}){const f=o.useRef(null),g=o.useRef(null),v=o.useRef(null),k=o.useRef(!1),[h,A]=o.useState(null),[$,N]=o.useState("");o.useEffect(()=>{const D=f.current;D&&(D.querySelectorAll("[title]").forEach(Q=>{const j=Q.getAttribute("title");j&&(Q.getAttribute("aria-label")||Q.setAttribute("aria-label",j),Q.removeAttribute("title"))}),D.querySelectorAll("svg title").forEach(Q=>Q.remove()))}),o.useLayoutEffect(()=>{if(!h)return;const D=g.current;if(!D)return;const Q=12,j=14,se=D.getBoundingClientRect(),te=window.innerWidth-se.width-Q,ee=window.innerHeight-se.height-Q;let U=h.mouseX+j,J=h.mouseY+j,ce,C;if(!s&&f.current){const _=f.current.getBoundingClientRect(),ae=_.left+_.width/2,B=_.top+_.height/2;l==="top"?(U=ae-se.width/2,J=_.top-se.height-j,C=se.height-1):l==="left"?(U=_.left-se.width-j,J=B-se.height/2,ce=se.width-1):l==="right"?(U=_.right+j,J=B-se.height/2,ce=-7):(U=ae-se.width/2,J=_.bottom+j,C=-7)}if(s&&(U>te&&(U=h.mouseX-se.width-j),J>ee&&(J=h.mouseY-se.height-j)),U=Math.min(Math.max(Q,U),Math.max(Q,te)),J=Math.min(Math.max(Q,J),Math.max(Q,ee)),!s&&f.current){const _=f.current.getBoundingClientRect(),ae=_.left+_.width/2,B=_.top+_.height/2;l==="top"||l==="bottom"?ce=Math.min(Math.max(14,ae-U),se.width-14):C=Math.min(Math.max(14,B-J),se.height-14)}(Math.abs(U-h.x)>.5||Math.abs(J-h.y)>.5||ce!==h.arrowX||C!==h.arrowY)&&A(_=>_&&{..._,x:U,y:J,arrowX:ce,arrowY:C})},[s,l,h]);const T=()=>{v.current&&(window.clearTimeout(v.current),v.current=null)},x=(D,Q)=>{if(!Ii()||k.current)return;const j=f.current;if(j&&!xn(j)){if(n){const se=Oi(j);if(!se)return;N(se)}!n&&!r||A({mouseX:D,mouseY:Q,x:D+14,y:Q+14})}},y=()=>{const D=f.current;if(!D)return;const Q=D.getBoundingClientRect();x(Q.left+Q.width/2,Q.bottom)},L=()=>{T(),A(null)},w=()=>{if(!a){L();return}T(),v.current=window.setTimeout(()=>A(null),120)},W=()=>{yn(),k.current=!0,L()},X=()=>{k.current=!1};o.useEffect(()=>{if(!h)return;if(xn(f.current)){A(null);return}const D=()=>A(null),Q=()=>{yn(),k.current=!0,A(null)};document.addEventListener("pointerdown",Q,!0),document.addEventListener("click",Q,!0),document.addEventListener("scroll",D,!0),window.addEventListener("blur",D),document.addEventListener("visibilitychange",D),document.addEventListener("keydown",D,!0);const j=new MutationObserver(()=>{xn(f.current)&&A(null)});return j.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["role","aria-modal","aria-hidden","class"]}),()=>{document.removeEventListener("pointerdown",Q,!0),document.removeEventListener("click",Q,!0),document.removeEventListener("scroll",D,!0),window.removeEventListener("blur",D),document.removeEventListener("visibilitychange",D),document.removeEventListener("keydown",D,!0),j.disconnect()}},[h]),o.useEffect(()=>{const D=()=>yn(),Q=()=>{yn(),k.current=!0,A(null)};return document.addEventListener("pointerdown",D,!0),document.addEventListener("click",D,!0),document.addEventListener("keydown",D,!0),window.addEventListener(Uo,Q),()=>{document.removeEventListener("pointerdown",D,!0),document.removeEventListener("click",D,!0),document.removeEventListener("keydown",D,!0),window.removeEventListener(Uo,Q)}},[]);const Z=n?$:r;return t.jsxs(t.Fragment,{children:[t.jsx(b,{ref:D=>{f.current=D},className:c,style:u,onMouseEnter:D=>{T(),X(),s?x(D.clientX,D.clientY):y()},onMouseMove:D=>{h&&s&&x(D.clientX,D.clientY)},onMouseDown:W,onClick:W,onMouseLeave:()=>{X(),w()},onFocus:y,onBlur:L,children:e}),h&&Z&&!xn(f.current)?ct.createPortal(t.jsxs("div",{ref:g,role:"tooltip",className:d,onMouseEnter:a?T:void 0,onMouseLeave:a?w:void 0,style:{position:"fixed",top:h.y,left:h.x,zIndex:9999,background:"var(--bg-card)",border:"1px solid var(--border)",borderRadius:6,padding:"5px 10px",fontSize:12,color:"var(--text-main)",boxShadow:"0 4px 16px rgba(0,0,0,0.35)",pointerEvents:a?"auto":"none",maxWidth:"min(420px, calc(100vw - 24px))",whiteSpace:"normal",lineHeight:1.6,overflowWrap:"anywhere",...m},children:[i&&t.jsx("span",{"aria-hidden":"true",style:{position:"absolute",width:12,height:12,background:(m==null?void 0:m.background)??"var(--bg-card)",borderLeft:l==="right"?(m==null?void 0:m.border)??"1px solid var(--border)":void 0,borderTop:l==="bottom"||l==="right"?(m==null?void 0:m.border)??"1px solid var(--border)":void 0,borderRight:l==="left"?(m==null?void 0:m.border)??"1px solid var(--border)":void 0,borderBottom:l==="top"||l==="left"?(m==null?void 0:m.border)??"1px solid var(--border)":void 0,transform:"rotate(45deg)",left:h.arrowX===void 0?void 0:h.arrowX-6,top:h.arrowY===void 0?void 0:h.arrowY-6,zIndex:-1}}),Z]}),document.body):null]})}function Vo(e){if(e!==void 0)return typeof e=="number"?`${e}px`:e}const Hi="inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap leading-none font-medium transition-all duration-150 focus:outline-none disabled:opacity-50 rounded-lg",Bi={primary:"border border-[var(--border)] text-[var(--text-main)] hover:border-[var(--border)] hover:bg-[var(--bg-input)] active:scale-[0.98] transition-colors",secondary:"border border-[var(--border)] text-[var(--text-main)] hover:border-[var(--border)] hover:bg-[var(--bg-input)] active:scale-[0.98] transition-colors",danger:"border border-[var(--border)] text-[var(--danger)] hover:border-[var(--danger)] hover:bg-[var(--danger-bg)] active:scale-[0.98] transition-colors",ghost:"text-[var(--text-secondary)] hover:opacity-70",icon:"text-[var(--text-muted)] hover:text-[var(--primary)] hover:bg-primary/5"},Fi="border border-[var(--border)] text-[var(--text-muted)] shadow-sm shadow-black/5 hover:border-[var(--border)] hover:bg-[var(--bg-input)] hover:text-[var(--primary)] active:scale-[0.98] transition-colors",Pi={xs:"h-8 px-2.5 text-xs",sm:"h-9 px-3.5 text-xs",md:"h-10 px-3.5 text-sm",lg:"h-11 px-4 text-sm font-semibold"},_i={xs:"h-8 w-8",sm:"h-9 w-9",md:"h-10 w-10",lg:"h-10 w-10"},zi={primary:{background:"var(--bg-card)"},secondary:{background:"var(--bg-card)"},danger:{background:"var(--bg-card)"},ghost:{},icon:{}};function $a(e){return typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map($a).join(" ").trim():o.isValidElement(e)?$a(e.props.children):""}function Wi(e){return o.Children.toArray(e).find(o.isValidElement)??null}function Ue({variant:e="primary",size:r="md",loading:n=!1,icon:a,tooltip:s,iconOnly:l,height:i,padding:c,children:d,className:u="",disabled:m,style:b,...f}){const g=o.useContext(jo),v=l??g.iconOnly??e==="icon",k=g.compact??!1,h=g.headerAction??!1,A=h&&r==="md"?"sm":k&&!h&&r==="md"?"xs":r,$=e==="icon"||v,N=h&&$,T=$a(d),x=s??f.title??f["aria-label"]??(v?T:void 0),y=x?void 0:f.title,L=f["aria-label"]??(typeof x=="string"?x:T||void 0),w=n?null:a??(v?Wi(d):null),W=t.jsxs("button",{...f,title:y,"aria-label":L,"data-variant":e,"data-size":A,"data-icon":$?"true":void 0,disabled:m||n,className:`${Hi} ${N?Fi:Bi[e]} ${$?_i[A]:Pi[A]} ${k&&!$?"px-2.5":""} ${u}`,style:{...zi[e],height:Vo(i),padding:Vo(c),...b,...h&&!$?{height:"var(--page-header-control-height, 34px)",padding:"0 var(--page-header-control-padding-x, 10px)",borderRadius:"8px"}:null,...N?{width:"var(--page-header-control-height, 40px)",height:"var(--page-header-control-height, 40px)",padding:0,background:"var(--bg-card)",borderRadius:"8px"}:null},children:[n?t.jsx("span",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):w,!v&&d]});return x?t.jsx(Yt,{as:"span",content:x,className:"inline-flex shrink-0",children:W}):W}const dt={background:"color-mix(in srgb, var(--text-muted) 26%, var(--bg-input))"};function wn({rows:e=8,columns:r=7,showToolbar:n=!0,showPagination:a=!0,compact:s=!1,className:l=""}){const i=Math.max(3,Math.min(r,12)),c=Math.max(3,Math.min(e,20)),d=s?"px-2 py-2":"px-3 py-2.5",u=s?"px-2 py-2":"px-3 py-3";return t.jsxs("div",{className:`w-full min-w-0 overflow-hidden rounded-lg border border-[var(--border)] bg-[var(--bg-card)] ${l}`,"aria-busy":"true","aria-label":"Cargando tabla",children:[n&&t.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-[var(--border)] px-3 py-2",children:[t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[t.jsx("div",{className:"h-7 w-14 shrink-0 animate-pulse rounded-md",style:dt}),t.jsx("div",{className:"h-7 max-w-md flex-1 animate-pulse rounded-md",style:dt})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[t.jsx("div",{className:"h-7 w-7 animate-pulse rounded-md",style:dt}),t.jsx("div",{className:"h-7 w-7 animate-pulse rounded-md",style:dt})]})]}),t.jsx("div",{className:"overflow-x-auto",children:t.jsxs("div",{className:"min-w-full",style:{display:"grid",gridTemplateColumns:`repeat(${i}, minmax(96px, 1fr))`},children:[Array.from({length:i}).map((m,b)=>t.jsx("div",{className:`${u} border-b border-[var(--border)]`,style:{background:"color-mix(in srgb, var(--bg-input) 55%, transparent)"},children:t.jsx("div",{className:"h-3 animate-pulse rounded-md",style:{...dt,width:`${48+b*17%40}%`}})},`h-${b}`)),Array.from({length:c}).map((m,b)=>Array.from({length:i}).map((f,g)=>t.jsx("div",{className:`${d} ${b<c-1?"border-b border-[var(--border)]":""}`,children:t.jsx("div",{className:"h-3.5 animate-pulse rounded-md",style:{...dt,width:`${46+(b*13+g*11)%42}%`,minWidth:28}})},`c-${b}-${g}`)))]})}),a&&t.jsxs("div",{className:"flex items-center justify-between gap-3 border-t border-[var(--border)] px-3 py-2",style:{background:"color-mix(in srgb, var(--bg-input) 40%, transparent)"},children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"h-3 w-28 animate-pulse rounded-md",style:dt}),t.jsx("div",{className:"h-7 w-14 animate-pulse rounded-md",style:dt})]}),t.jsx("div",{className:"flex items-center gap-1",children:Array.from({length:4}).map((m,b)=>t.jsx("div",{className:"h-7 w-7 animate-pulse rounded-md",style:dt},b))}),t.jsx("div",{className:"h-3 w-16 animate-pulse rounded-md",style:dt})]})]})}function ji({size:e="md"}){const r=e==="sm"?"h-7 w-7":"h-9 w-9";return t.jsx("div",{className:`${r} animate-spin rounded-full border-2 border-[var(--border)] border-t-[var(--primary)]`,"aria-hidden":!0})}function qi({logoSrc:e,logoAlt:r}){return e?t.jsxs("span",{className:"relative flex h-16 w-16 items-center justify-center","aria-hidden":!1,children:[t.jsx("span",{className:"absolute inset-0 rounded-2xl opacity-40 blur-xl",style:{background:"radial-gradient(circle, color-mix(in srgb, var(--primary) 45%, transparent) 0%, transparent 70%)"}}),t.jsx("img",{src:e,alt:r,className:"relative h-14 w-14 rounded-2xl object-contain shadow-sm shadow-black/10"})]}):null}function Yo({variant:e="page",title:r="Cargando...",description:n,logoSrc:a,logoAlt:s,appearance:l="card",rows:i=6,columns:c=7,children:d,className:u=""}){if(e==="table")return t.jsx(wn,{rows:i,columns:c,className:u});if(e==="sections")return t.jsx(Ui,{rows:i});if(e==="cards")return t.jsx(Vi,{rows:i});const m=s||(typeof r=="string"?r:"Aplicación"),b=l==="bare",f=t.jsxs("div",{className:`flex flex-col items-center text-center ${b?"gap-5":"gap-3"}`,children:[a?t.jsx(qi,{logoSrc:a,logoAlt:m}):null,t.jsx(ji,{size:b?"md":"sm"}),t.jsxs("div",{className:b?"space-y-1.5":"",children:[t.jsx("p",{className:b?"text-base font-semibold tracking-tight text-[var(--text-main)]":"text-sm font-semibold text-[var(--text-main)]",children:r}),n?t.jsx("p",{className:b?"text-sm font-medium text-[var(--text-muted)]":"mt-1 text-xs text-[var(--text-muted)]",children:n}):null,d&&t.jsx("div",{className:"mt-1 text-xs text-[var(--text-muted)]",children:d})]})]});return b?t.jsx("div",{className:`flex min-h-[240px] w-full items-center justify-center p-8 ${u}`,role:"status","aria-live":"polite","aria-busy":"true",children:f}):t.jsx("div",{className:`flex min-h-[240px] items-center justify-center rounded-lg border border-[var(--border)] bg-[var(--bg-card)] p-6 ${u}`,role:"status","aria-live":"polite","aria-busy":"true",children:f})}function Ui({rows:e}){return t.jsx(wn,{rows:e,columns:7})}function Vi({rows:e}){return t.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:Array.from({length:e}).map((r,n)=>t.jsxs("div",{className:"rounded-lg border border-[var(--border)] bg-[var(--bg-card)] p-4",children:[t.jsx("div",{className:"h-4 w-2/3 animate-pulse rounded-md",style:dt}),t.jsx("div",{className:"mt-3 h-3 w-full animate-pulse rounded-md",style:dt}),t.jsx("div",{className:"mt-2 h-3 w-4/5 animate-pulse rounded-md",style:dt})]},n))})}function Xo(e){const r=e.split("/").filter(Boolean);return(r[r.length-1]??e).replace(/^lv_/,"").split(/[-_]/).filter(Boolean).map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(" ")}function Ko(e){return e.normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().trim()}function Yi(e){return[e.label,Xo(e.service),e.description,e.service].filter(Boolean).join(" ")}function Xi(e){return typeof e=="function"?e:e.default}function Ki(e,r){return t.jsx("div",{className:"flex min-h-[220px] items-center justify-center rounded-lg border border-[var(--border)] bg-[var(--bg-card)] p-6 text-center",children:t.jsxs("div",{className:"max-w-md",children:[t.jsx("p",{className:"text-sm font-semibold text-[var(--text-main)]",children:"No se pudo cargar este modulo"}),t.jsx("p",{className:"mt-1 text-xs text-[var(--text-muted)]",children:e.message}),t.jsx(Ue,{className:"mt-4",height:36,padding:"0 14px",onClick:r,children:"Reintentar"})]})})}function Gi({parentPanel:e,parentPanelComponent:r,renderParentPanel:n,parent:a,context:s,links:l,moduleRegistry:i,loadModule:c,activeService:d,initialService:u,onActiveServiceChange:m,canAccess:b,keepAlive:f=!0,title:g,subtitle:v,emptyState:k,loadingState:h,errorState:A=Ki,renderTabLabel:$,searchableTabs:N="auto",tabsSearchThreshold:T=6,tabsSearchPlaceholder:x="Buscar modulo...",tabsSearchValue:y,onTabsSearchChange:L,emptySearchState:w,showTabCount:W=!0,className:X="",parentClassName:Z="",contentClassName:D="",tabsClassName:Q=""}){var Et;const j=o.useMemo(()=>l.filter(le=>!le.hidden&&((b==null?void 0:b(le,s))??!0)),[b,s,l]),se=(Et=j.find(le=>!le.disabled))==null?void 0:Et.service,[te,ee]=o.useState(u??se??""),[U,J]=o.useState({}),[ce,C]=o.useState({}),[_,ae]=o.useState(""),[B,I]=o.useState(!1),E=o.useRef(ce),oe=o.useRef(0),K=y??_,Y=Ko(K),S=N===!0||N==="auto"&&j.length>=T,H=S&&K.trim().length>0,O=o.useMemo(()=>Y?j.filter(le=>Ko(Yi(le)).includes(Y)):j,[Y,j]),re=d??te,z=j.find(le=>le.service===re)??j.find(le=>!le.disabled);o.useEffect(()=>{!z&&se&&ee(se)},[se,z]),o.useEffect(()=>{E.current=ce},[ce]);const de=le=>{le.disabled||(d||ee(le.service),m==null||m(le.service,le))},he=le=>{y===void 0&&ae(le),L==null||L(le)},ie=(le,Fe)=>{const ze=O.filter(Ve=>!Ve.disabled),ft=ze.findIndex(Ve=>Ve.service===Fe.service);ft<0||((le.key==="ArrowRight"||le.key==="ArrowDown")&&(le.preventDefault(),de(ze[(ft+1)%ze.length])),(le.key==="ArrowLeft"||le.key==="ArrowUp")&&(le.preventDefault(),de(ze[(ft-1+ze.length)%ze.length])),le.key==="Home"&&(le.preventDefault(),de(ze[0])),le.key==="End"&&(le.preventDefault(),de(ze[ze.length-1])))},ge=o.useCallback(()=>{if(!z)return;const le=z.service,Fe=E.current[le];if(Fe!=null&&Fe.loading||Fe!=null&&Fe.component&&f)return;const ze=(i==null?void 0:i[le])??c;if(!ze){C(Ve=>({...Ve,[le]:{loading:!1,error:new Error(`No module loader found for service "${le}".`)}}));return}const ft=++oe.current;C(Ve=>({...Ve,[le]:{...Ve[le],loading:!0,error:void 0}})),ze(z,s).then(Ve=>{if(ft!==oe.current&&!f)return;const Mt=Xi(Ve);C(bt=>({...bt,[le]:{component:Mt,loading:!1}}))}).catch(Ve=>{const Mt=Ve instanceof Error?Ve:new Error(String(Ve));C(bt=>({...bt,[le]:{...bt[le],loading:!1,error:Mt}}))})},[s,f,c,i,z]);o.useEffect(ge,[ge]);const Me=z?U[z.service]??null:null,$e=z?ce[z.service]:void 0,Dt=$e==null?void 0:$e.component,ut=le=>{z&&J(Fe=>({...Fe,[z.service]:le}))},Re=()=>{z&&J(le=>({...le,[z.service]:null}))},It={context:s,parent:a,links:l,visibleLinks:j,filteredLinks:O,selectedLink:z,selectedService:z==null?void 0:z.service,activeItemId:Me,tabsSearch:K,onSelectService:de,onOpenDetail:ut,onBackToList:Re},Ct=n?n(It):r?t.jsx(r,{...It}):e;return t.jsxs("section",{className:`grid min-h-[520px] gap-4 lg:grid-cols-[minmax(260px,360px)_minmax(0,1fr)] ${X}`,children:[t.jsx("aside",{className:`min-w-0 rounded-lg border border-[var(--border)] bg-[var(--bg-card)] p-4 ${Z}`,children:Ct}),t.jsxs("div",{className:`relative min-w-0 overflow-visible rounded-lg border border-[var(--border)] bg-[var(--bg-card)] ${D}`,children:[(g||v||S||W)&&t.jsx("div",{className:"relative border-b border-[var(--border)] px-4 py-3",children:t.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[g&&t.jsx("h2",{className:"truncate text-sm font-semibold text-[var(--text-main)]",children:g}),v&&t.jsx("p",{className:"mt-1 line-clamp-2 text-xs text-[var(--text-muted)]",children:v})]}),(S||W)&&t.jsxs("div",{className:"flex min-w-0 flex-shrink-0 items-center justify-end gap-2",children:[W&&t.jsxs("span",{className:"hidden text-xs font-semibold text-[var(--text-muted)] transition-opacity duration-200 sm:inline",children:[O.length," / ",j.length]}),S&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:`origin-right overflow-hidden transition-[width,opacity,transform] duration-200 ease-out ${B?"w-[min(20rem,44vw)] translate-x-0 opacity-100":"w-0 translate-x-2 opacity-0"}`,"aria-hidden":!B,children:t.jsx(Wo,{value:K,onChange:he,placeholder:x,className:"w-full",autoFocus:B,forceExpanded:!0,onEscape:()=>I(!1),size:"sm",inputTabIndex:B?0:-1})}),t.jsx("button",{type:"button","aria-label":B?"Cerrar busqueda":"Buscar tabs","aria-expanded":B,onClick:()=>{B&&K&&he(""),I(le=>!le)},className:`inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border transition-all duration-200 hover:scale-[1.03] active:scale-95 ${B||H?"border-[var(--primary)] bg-[var(--bg-input)] text-[var(--text-main)] shadow-sm":"border-[var(--border)] text-[var(--text-muted)] hover:bg-[var(--bg-input)] hover:text-[var(--text-main)]"}`,children:t.jsx("span",{className:"grid h-4 w-4 place-items-center transition-transform duration-200",children:B||H?t.jsx(q.HiXMark,{className:"h-4 w-4"}):t.jsx(q.HiMagnifyingGlass,{className:"h-4 w-4"})})})]})]})]})}),t.jsx("div",{role:"tablist","aria-label":g??"Modulos relacionados",className:`flex gap-1 overflow-x-auto border-b border-[var(--border)] bg-[var(--bg-input)] px-2 py-1.5 transition-colors duration-200 ${Q}`,children:O.length>0?O.map(le=>{const Fe=le.service===(z==null?void 0:z.service);return t.jsx("button",{type:"button",role:"tab","aria-selected":Fe,disabled:le.disabled,onClick:()=>de(le),onKeyDown:ze=>ie(ze,le),className:`inline-flex h-9 min-w-max items-center gap-2 rounded-md border px-3 text-xs font-semibold transition-all duration-200 disabled:cursor-not-allowed disabled:opacity-50 ${Fe?"border-[var(--primary)] bg-[var(--bg-card)] text-[var(--text-main)] shadow-sm":"border-transparent text-[var(--text-muted)] hover:bg-[var(--bg-card)] hover:text-[var(--text-main)]"}`,children:$?$(le,Fe):t.jsxs(t.Fragment,{children:[le.icon,t.jsx("span",{children:le.label??Xo(le.service)}),le.badge&&t.jsx("span",{className:"rounded-full bg-[var(--bg-input)] px-1.5 py-0.5 text-[10px] text-[var(--text-muted)]",children:le.badge})]})},le.service)}):t.jsx("div",{className:"flex min-h-9 flex-1 items-center rounded-md border border-dashed border-[var(--border)] px-3 text-xs text-[var(--text-muted)]",children:w??"No hay modulos que coincidan con la busqueda."})}),(z==null?void 0:z.description)&&t.jsx("div",{className:"border-b border-[var(--border)] px-4 py-2 text-xs text-[var(--text-muted)]",children:z.description}),t.jsxs("div",{className:"min-h-[420px] p-4",children:[!z&&(k??t.jsx("div",{className:"flex min-h-[220px] items-center justify-center rounded-lg border border-dashed border-[var(--border)] text-sm text-[var(--text-muted)]",children:"No hay modulos disponibles."})),z&&($e==null?void 0:$e.loading)&&(h??t.jsx(Yo,{title:"Cargando modulo..."})),z&&($e==null?void 0:$e.error)&&A($e.error,ge),z&&Dt&&!($e!=null&&$e.loading)&&!($e!=null&&$e.error)&&t.jsx(Dt,{context:s,parent:a,link:z,activeItemId:Me,onOpenDetail:ut,onBackToList:Re})]})]})]})}const Zi={info:{color:"#2563eb",background:"rgba(59, 130, 246, 0.1)",border:"rgba(59, 130, 246, 0.24)",icon:t.jsx(q.HiInformationCircle,{className:"h-5 w-5"})},success:{color:"#047857",background:"rgba(16, 185, 129, 0.1)",border:"rgba(16, 185, 129, 0.24)",icon:t.jsx(q.HiCheckCircle,{className:"h-5 w-5"})},warning:{color:"#b45309",background:"rgba(245, 158, 11, 0.12)",border:"rgba(245, 158, 11, 0.26)",icon:t.jsx(q.HiExclamationTriangle,{className:"h-5 w-5"})},danger:{color:"var(--danger)",background:"var(--danger-bg)",border:"color-mix(in srgb, var(--danger) 20%, var(--border))",icon:t.jsx(q.HiExclamationCircle,{className:"h-5 w-5"})},neutral:{color:"var(--text-secondary)",background:"var(--bg-input)",border:"var(--border)",icon:t.jsx(q.HiInformationCircle,{className:"h-5 w-5"})}};function Qi({variant:e="info",title:r,children:n,icon:a,action:s,onDismiss:l,className:i=""}){const c=Zi[e];return t.jsxs("div",{role:e==="danger"||e==="warning"?"alert":"status",className:`flex items-start gap-3 rounded-lg border px-3 py-3 ${i}`,style:{background:c.background,borderColor:c.border},children:[t.jsx("div",{className:"mt-0.5 shrink-0",style:{color:c.color},children:a??c.icon}),t.jsxs("div",{className:"min-w-0 flex-1",children:[r&&t.jsx("div",{className:"text-sm font-semibold text-[var(--text-main)]",children:r}),n&&t.jsx("div",{className:"mt-0.5 text-sm leading-5 text-[var(--text-secondary)]",children:n}),s&&t.jsx("div",{className:"mt-3",children:s})]}),l&&t.jsx(Ue,{variant:"icon",size:"xs","aria-label":"Cerrar alerta",onClick:l,className:"-mr-1 -mt-1",children:t.jsx(q.HiXMark,{className:"h-4 w-4"})})]})}const Go=["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"],Ji=["Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"],Ri=["lu","ma","mi","ju","vi","sá","do"],Zo=6;function Aa(e,r,n){return`${e}-${String(r).padStart(2,"0")}-${String(n).padStart(2,"0")}`}function ec(){const e=new Date;return Aa(e.getFullYear(),e.getMonth()+1,e.getDate())}function Qo(e){const[r,n,a]=e.split("-").map(Number);return{year:r,month:n,day:a}}function tc(e){if(!e)return"Seleccionar fecha";const{year:r,month:n,day:a}=Qo(e);return!r||!n||!a?"Seleccionar fecha":`${String(a).padStart(2,"0")} ${Go[n-1]} ${r}`}function rc({value:e,onChange:r,minDate:n,displayMode:a="inline",className:s=""}){const l=ec(),c=Qo(e||l),d=a==="popover",[u,m]=o.useState(!1),b=o.useRef(null),[f,g]=o.useState({horizontal:"left",vertical:"bottom"}),[v,k]=o.useState(c.year),[h,A]=o.useState(c.month),[$,N]=o.useState("days"),T=16,[x,y]=o.useState(0),L=v-7+x,w=Array.from({length:T},(ee,U)=>L+U);o.useEffect(()=>{if(!d||!u||!b.current)return;const ee=b.current.getBoundingClientRect(),U=8,J=280,ce=340,C=ee.left+J>window.innerWidth-U,_=ee.right-J>=U,ae=ee.bottom+8+ce>window.innerHeight-U,B=ee.top-8-ce>=U;g({horizontal:C&&_?"right":"left",vertical:ae&&B?"top":"bottom"})},[d,u]),o.useEffect(()=>{if(!d||!u)return;function ee(J){b.current&&(b.current.contains(J.target)||m(!1))}function U(J){J.key==="Escape"&&m(!1)}return document.addEventListener("mousedown",ee),document.addEventListener("keydown",U),()=>{document.removeEventListener("mousedown",ee),document.removeEventListener("keydown",U)}},[d,u]);function W(){h===1?(k(ee=>ee-1),A(12)):A(ee=>ee-1)}function X(){h===12?(k(ee=>ee+1),A(1)):A(ee=>ee+1)}const Z=(new Date(v,h-1,1).getDay()+6)%7,D=new Date(v,h,0).getDate(),Q=[...Array(Z).fill(null),...Array.from({length:D},(ee,U)=>U+1)];for(;Q.length<Zo*7;)Q.push(null);const j=Q.slice(0,Zo*7);function se(ee){const U=Aa(v,h,ee);n&&U<n||(r(U),d&&m(!1))}const te=t.jsx("div",{className:`bonsaif-calendar bonsaif-calendar-picker ${s}`.trim(),children:t.jsxs("div",{className:"bonsaif-cal-shell",children:[t.jsx("div",{className:"bonsaif-cal-toolbar",children:$==="days"?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn",onClick:W,"aria-label":"Mes anterior",children:t.jsx(q.HiChevronLeft,{size:16})}),t.jsxs("button",{type:"button",className:"bonsaif-cal-title-btn",onClick:()=>{N("years"),y(0)},children:[t.jsxs("span",{className:"bonsaif-cal-title",children:[Go[h-1]," ",v]}),t.jsx(q.HiChevronDown,{size:13})]}),t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn",onClick:X,"aria-label":"Mes siguiente",children:t.jsx(q.HiChevronRight,{size:16})})]}):t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn",onClick:()=>y(ee=>ee-T),"aria-label":"Años anteriores",children:t.jsx(q.HiChevronLeft,{size:16})}),t.jsx("button",{type:"button",className:"bonsaif-cal-title-btn",onClick:()=>N("days"),children:t.jsxs("span",{className:"bonsaif-cal-title",children:[w[0]," – ",w[w.length-1]]})}),t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn",onClick:()=>y(ee=>ee+T),"aria-label":"Años siguientes",children:t.jsx(q.HiChevronRight,{size:16})})]})}),$==="years"?t.jsxs("div",{className:"bonsaif-cal-picker-years",children:[t.jsx("div",{className:"bonsaif-cal-picker-months",children:Ji.map((ee,U)=>{const J=U+1===h;return t.jsx("button",{type:"button",className:`bonsaif-cal-pill-btn${J?" is-active":""}`,onClick:()=>A(U+1),children:ee},ee)})}),t.jsx("div",{className:"bonsaif-cal-picker-year-grid",children:w.map(ee=>{const U=ee===v,J=ee===new Date().getFullYear();return t.jsx("button",{type:"button",className:`bonsaif-cal-pill-btn${U?" is-active":""}${J&&!U?" is-today":""}`,onClick:()=>{k(ee),N("days")},children:ee},ee)})})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bonsaif-multi-weekdays bonsaif-cal-picker-weekdays",children:Ri.map(ee=>t.jsx("div",{className:"bonsaif-multi-weekday",children:ee},ee))}),t.jsx("div",{className:"bonsaif-cal-picker-days",children:j.map((ee,U)=>{if(ee===null)return t.jsx("div",{className:"bonsaif-multi-day bonsaif-multi-day-hidden"},U);const J=Aa(v,h,ee),ce=J===e,C=J===l,_=!!(n&&J<n);return t.jsx("div",{className:`bonsaif-multi-day${ce?" bonsaif-multi-day-selected":""}${C?" bonsaif-multi-day-today":""}${_?" bonsaif-multi-day-disabled":""}`,children:t.jsx("button",{type:"button",className:"bonsaif-multi-day-btn",disabled:_,"aria-pressed":ce,onClick:()=>!_&&se(ee),children:ee})},U)})})]})]})});return d?t.jsxs("div",{ref:b,className:`relative w-full ${s}`.trim(),children:[t.jsxs("button",{type:"button",onClick:()=>m(ee=>!ee),className:"bonsaif-cal-trigger","data-open":u?"true":"false",children:[t.jsxs("span",{className:"inline-flex items-center gap-2 min-w-0",children:[t.jsx(q.HiCalendarDays,{className:"w-4 h-4 text-[var(--text-muted)]"}),t.jsx("span",{className:"truncate",children:tc(e)})]}),t.jsx(q.HiChevronDown,{className:`w-4 h-4 text-[var(--text-muted)] transition-transform ${u?"rotate-180":""}`})]}),u&&t.jsx("div",{className:"absolute z-50",style:{...f.horizontal==="left"?{left:0}:{right:0},...f.vertical==="bottom"?{top:"calc(100% + 8px)"}:{bottom:"calc(100% + 8px)"}},children:te})]}):te}const nc={sm:"h-4 w-4",md:"h-5 w-5"};function ac(e,r){if(typeof e=="function"){e(r);return}e&&(e.current=r)}const Nn=o.forwardRef(function({label:r,description:n,error:a,size:s="md",indeterminate:l=!1,className:i="",containerClassName:c="",disabled:d,...u},m){const b=o.useRef(null);return o.useEffect(()=>{b.current&&(b.current.indeterminate=l)},[l]),t.jsxs("label",{className:`group inline-flex items-start gap-2.5 ${d?"cursor-not-allowed opacity-60":"cursor-pointer"} ${c}`,children:[t.jsxs("span",{className:"relative mt-0.5 inline-flex shrink-0",children:[t.jsx("input",{...u,ref:f=>{b.current=f,ac(m,f)},type:"checkbox",disabled:d,"aria-checked":l?"mixed":u["aria-checked"],"aria-invalid":!!a||u["aria-invalid"],className:`peer ${nc[s]} appearance-none rounded border border-[var(--border)] bg-[var(--bg-input)] transition-colors checked:border-[var(--primary)] checked:bg-[var(--primary)] focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--primary)]/40 ${i}`}),t.jsx(q.HiCheck,{className:"pointer-events-none absolute left-1/2 top-1/2 h-3.5 w-3.5 -translate-x-1/2 -translate-y-1/2 scale-75 text-[var(--primary-fg)] opacity-0 transition peer-checked:scale-100 peer-checked:opacity-100 peer-aria-checked:mixed:scale-100 peer-aria-checked:mixed:opacity-100"})]}),(r||n||a)&&t.jsxs("span",{className:"min-w-0",children:[r&&t.jsx("span",{className:"block text-sm font-medium leading-5 text-[var(--text-main)]",children:r}),n&&!a&&t.jsx("span",{className:"block text-xs leading-5 text-[var(--text-muted)]",children:n}),a&&t.jsx("span",{className:"block text-xs leading-5 text-[var(--danger)]",children:a})]})]})});function Jo(e){const r=document.createElement("textarea");r.value=e,r.style.position="fixed",r.style.opacity="0",r.style.pointerEvents="none",document.body.appendChild(r),r.select(),document.execCommand("copy"),document.body.removeChild(r)}async function oc(e){var r;if((r=navigator.clipboard)!=null&&r.writeText){await navigator.clipboard.writeText(e);return}Jo(e)}function sc(e){return typeof e=="function"?e():e}function La({value:e,resetDelay:r=2e3,title:n,copiedTitle:a="Copiado",copiedLabel:s,icon:l=t.jsx(q.HiClipboardDocument,{size:14}),copiedIcon:i=t.jsx(q.HiCheck,{size:14}),stopPropagation:c=!0,onCopied:d,onCopyError:u,className:m="",style:b,children:f,onClick:g,type:v="button",...k}){const[h,A]=o.useState(!1),$=o.useRef(null);o.useEffect(()=>()=>{$.current&&window.clearTimeout($.current)},[]);function N(x){A(!0),d==null||d(x),$.current&&window.clearTimeout($.current),$.current=window.setTimeout(()=>{A(!1),$.current=null},r)}async function T(x){var L;if(c&&x.stopPropagation(),g==null||g(x),x.defaultPrevented)return;const y=sc(e);if(y)try{await oc(y),N(y)}catch(w){try{Jo(y),N(y)}catch(W){u==null||u(W,y);return}(L=navigator.clipboard)!=null&&L.writeText||u==null||u(w,y)}}return t.jsxs("button",{...k,type:v,onClick:T,title:h?a:n,"aria-label":k["aria-label"]??(h?a:n),"data-copied":h?"true":void 0,className:`relative inline-flex h-7 shrink-0 items-center justify-center gap-1.5 rounded-md transition-all duration-200 ${f?"min-w-7 px-2":"w-7"} ${m}`,style:{cursor:"pointer",background:h?"rgba(22,163,74,0.15)":"var(--bg-card)",border:h?"1px solid rgba(22,163,74,0.4)":"1px solid var(--border)",color:h?"#16a34a":"var(--text-secondary)",boxShadow:h?"0 0 0 3px rgba(22,163,74,0.12)":"none",...b},children:[t.jsx("span",{className:"inline-flex items-center justify-center transition-all duration-150",style:{transform:h?"scale(1.15)":"scale(1)"},children:h?i:l}),f&&t.jsx("span",{className:"text-xs font-semibold leading-none",children:h?s??f:f})]})}function lc({code:e,children:r,title:n="Codigo",language:a,copyLabel:s="Copiar",copiedLabel:l="Copiado",className:i="",style:c,onCopied:d}){const u=(e??r??"").trim();return t.jsxs("div",{className:`overflow-hidden rounded-lg border ${i}`,style:{borderColor:"rgba(148, 163, 184, 0.22)",background:"#0f172a",color:"#e2e8f0",...c},children:[t.jsxs("div",{className:"flex min-h-9 items-center justify-between gap-3 border-b px-3 py-1.5",style:{borderColor:"rgba(148, 163, 184, 0.18)",background:"#111827",color:"#94a3b8"},children:[t.jsx("span",{className:"min-w-0 truncate text-[11px] font-black uppercase tracking-[0.08em]",children:n}),t.jsx(La,{value:u,title:"Copiar codigo",copiedTitle:"Codigo copiado",copiedLabel:l,onCopied:d,className:"h-7 min-w-[72px] px-2",style:{background:"#182235",border:"1px solid rgba(148, 163, 184, 0.28)",color:"#f8fafc"},children:s})]}),t.jsx("pre",{className:"m-0 overflow-x-auto p-3 text-xs leading-6",style:{background:"#0f172a",color:"#e2e8f0",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace'},children:t.jsx("code",{className:a?`language-${a}`:void 0,children:u})})]})}function Pt({children:e,className:r="",style:n,as:a="span",followCursor:s=!1,placement:l="top"}){return t.jsx(Yt,{onlyWhenOverflow:!0,as:a,followCursor:s,placement:l,showArrow:!s,className:r,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0,...n},children:e})}function Da(e){if(e!==void 0)return typeof e=="number"?`${e}px`:e}function Ia(e){return e.normalize("NFD").replace(new RegExp("\\p{M}","gu"),"").toLowerCase()}function ic(e,r){if(!r.trim())return!0;const n=Ia(r);return Ia(e.label).includes(n)||!!(e.sublabel&&Ia(e.sublabel).includes(n))}function ar({value:e,onChange:r,options:n,status:a="default",ariaLabel:s,triggerVariant:l="default",showSelectedSublabel:i=!0,placeholder:c="Seleccionar…",emptyLabel:d,disabled:u=!1,className:m="",style:b,dropdownMinWidth:f,height:g=40,padding:v="0 10px",searchable:k=!0,minOptionsForSearch:h=6}){const[A,$]=o.useState(!1),[N,T]=o.useState(""),[x,y]=o.useState(-1),[L,w]=o.useState(!1),[W,X]=o.useState({}),Z=o.useRef(null),D=o.useRef(null),Q=o.useRef(null),j=o.useRef(null),se=k&&n.length>=h,te=n.find(K=>K.value===e)??null,ee=l==="ghost",U=a==="error"?"var(--danger)":A?"var(--primary)":"var(--border)",J=se&&N.trim()?n.filter(K=>ic(K,N)):n,ce=o.useCallback(()=>{const K=Z.current;if(!K)return;const Y=K.getBoundingClientRect(),S=se?272:212,H=window.innerHeight-Y.bottom,O=H<S&&Y.top>H;X({position:"fixed",left:Y.left,top:O?void 0:Y.bottom+4,bottom:O?window.innerHeight-Y.top+4:void 0,width:Y.width,minWidth:Da(f),zIndex:9999})},[f,se]);o.useEffect(()=>w(!0),[]),o.useEffect(()=>{if(!A)return;function K(Y){var H,O;const S=Y.target;!((H=Z.current)!=null&&H.contains(S))&&!((O=D.current)!=null&&O.contains(S))&&($(!1),T(""))}return document.addEventListener("mousedown",K),()=>document.removeEventListener("mousedown",K)},[A]),o.useEffect(()=>{A&&(y(-1),ce(),se&&setTimeout(()=>{var K;return(K=Q.current)==null?void 0:K.focus()},0))},[A,se,ce]),o.useEffect(()=>{if(A)return window.addEventListener("resize",ce),window.addEventListener("scroll",ce,!0),()=>{window.removeEventListener("resize",ce),window.removeEventListener("scroll",ce,!0)}},[A,ce]),o.useEffect(()=>{if(x<0||!j.current)return;const K=j.current.children[x];K==null||K.scrollIntoView({block:"nearest"})},[x]);const C=o.useCallback(K=>{r(K),$(!1),T("")},[r]),_=o.useRef(A);_.current=A;const ae=o.useRef(J);ae.current=J;const B=o.useRef(x);B.current=x;const I=o.useRef(d);I.current=d;const E=o.useRef(C);E.current=C,o.useEffect(()=>{function K(Y){var re,z;const S=document.activeElement,H=((re=Z.current)==null?void 0:re.contains(S))??!1,O=((z=D.current)==null?void 0:z.contains(S))??!1;if(!(!H&&!O)){if(!_.current){(Y.key==="Enter"||Y.key===" "||Y.key==="ArrowDown")&&(Y.preventDefault(),$(!0));return}switch(Y.key){case"ArrowDown":Y.preventDefault(),y(de=>Math.min(de+1,ae.current.length-1));break;case"ArrowUp":Y.preventDefault(),y(de=>Math.max(de-1,I.current?-1:0));break;case"Enter":{Y.preventDefault();const de=B.current,he=ae.current;de===-1&&I.current?E.current(""):he[de]&&!he[de].disabled&&E.current(he[de].value);break}case"Escape":Y.preventDefault(),Y.stopPropagation(),$(!1),T("");break}}}return document.addEventListener("keydown",K),()=>document.removeEventListener("keydown",K)},[]);const oe=t.jsxs("div",{ref:D,"data-bonsaif-select-dropdown":"true",className:"rounded-xl shadow-xl overflow-hidden",style:{...W,background:"var(--bg-card)",border:"1px solid var(--border)"},children:[se&&t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",style:{borderBottom:"1px solid var(--border)"},children:[t.jsx(q.HiMagnifyingGlass,{className:"w-3.5 h-3.5 flex-shrink-0",style:{color:"var(--text-muted)"}}),t.jsx("input",{ref:Q,value:N,onChange:K=>{T(K.target.value),y(-1)},placeholder:"Buscar…",className:"min-w-0 flex-1 text-sm bg-transparent outline-none",style:{color:"var(--text-main)"}}),N&&t.jsx("button",{type:"button",onMouseDown:K=>{K.preventDefault(),T("")},children:t.jsx(q.HiXMark,{className:"w-3.5 h-3.5",style:{color:"var(--text-muted)"}})})]}),t.jsxs("ul",{ref:j,role:"listbox",className:"overflow-y-auto",style:{maxHeight:se?220:180,scrollbarWidth:"thin",scrollbarColor:"var(--border) transparent",overscrollBehavior:"contain"},children:[d&&t.jsx("li",{role:"option","aria-selected":e==="",onMouseDown:K=>{K.preventDefault(),C("")},onMouseEnter:()=>y(-1),className:"flex items-center gap-2 px-3 py-2 cursor-pointer text-sm transition-colors",style:{background:x===-1&&!N.trim()?"var(--bg-hover)":"transparent",color:"var(--text-muted)",fontStyle:"italic"},children:d}),J.map((K,Y)=>{const H=Y===x,O=K.value===e;return t.jsxs("li",{role:"option","aria-selected":O,onMouseDown:re=>{re.preventDefault(),K.disabled||C(K.value)},onMouseEnter:()=>!K.disabled&&y(Y),className:"flex items-center gap-2 px-3 py-2 cursor-pointer text-sm transition-colors",style:{background:H?"var(--bg-hover)":O?"color-mix(in srgb, var(--primary) 6%, transparent)":"transparent",color:K.disabled?"var(--text-muted)":"var(--text-main)",cursor:K.disabled?"not-allowed":"pointer",boxShadow:O?"inset 2px 0 0 var(--primary)":void 0},children:[K.color&&t.jsx("span",{className:"flex-shrink-0 w-2.5 h-2.5 rounded-full",style:{background:K.color}}),t.jsxs("span",{className:"min-w-0 flex flex-1 items-baseline gap-1 overflow-hidden",children:[t.jsx(Pt,{className:"min-w-0 flex-1",children:K.label}),K.sublabel&&t.jsx(Pt,{className:"min-w-0 flex-shrink",style:{color:"var(--text-muted)",fontSize:12},children:K.sublabel})]}),K.badge&&t.jsx("span",{className:"text-xs flex-shrink-0",style:{color:"var(--text-muted)"},children:K.badge})]},K.value)}),J.length===0&&t.jsx("li",{className:"px-3 py-4 text-sm text-center",style:{color:"var(--text-muted)"},children:"Sin resultados"})]})]});return t.jsxs("div",{ref:Z,className:`relative ${m||"w-full"}`,style:b,children:[t.jsxs("button",{type:"button",disabled:u,onClick:()=>!u&&$(K=>!K),className:"flex w-full items-center gap-2 rounded-lg text-left text-sm transition-colors focus:outline-none",style:{height:Da(g),padding:Da(v),background:ee?"transparent":"var(--bg-input)",color:te?"var(--text-main)":"var(--text-muted)",border:ee?"1px solid transparent":`1px solid ${U}`,opacity:u?.5:1,cursor:u?"not-allowed":"pointer"},"aria-haspopup":"listbox","aria-expanded":A,"aria-label":s,children:[(te==null?void 0:te.color)&&t.jsx("span",{className:"flex-shrink-0 w-2.5 h-2.5 rounded-full",style:{background:te.color}}),t.jsx("span",{className:"min-w-0 flex flex-1 items-baseline gap-1 overflow-hidden",children:te?t.jsxs(t.Fragment,{children:[t.jsx(Pt,{className:"min-w-0 flex-1",children:te.label}),i&&te.sublabel&&t.jsx(Pt,{className:"min-w-0 flex-shrink",style:{color:"var(--text-muted)",fontSize:12},children:te.sublabel})]}):t.jsx(Pt,{className:"min-w-0 flex-1",children:c})}),te&&d?t.jsx("span",{role:"button",tabIndex:-1,onMouseDown:K=>{K.preventDefault(),K.stopPropagation(),C("")},className:"flex-shrink-0 rounded-full p-0.5 transition-colors hover:bg-black/10",style:{color:"var(--text-muted)"},children:t.jsx(q.HiXMark,{className:"w-3 h-3"})}):t.jsx(q.HiChevronDown,{className:"flex-shrink-0 w-4 h-4 transition-transform",style:{color:"var(--text-muted)",transform:A?"rotate(180deg)":"rotate(0deg)"}})]}),A&&L&&ct.createPortal(oe,document.body)]})}function kn(e){if(e!==void 0)return typeof e=="number"?`${e}px`:e}function cc({value:e,onChange:r,placeholder:n="Buscar...",className:a="",height:s=40,padding:l="0 10px 0 30px",iconLeft:i=10}){return t.jsxs("div",{className:`relative ${a}`,children:[t.jsx(q.HiMagnifyingGlass,{className:"absolute top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-[var(--text-muted)] pointer-events-none",style:{left:kn(i)}}),t.jsx("input",{type:"text",value:e,onChange:c=>r(c.target.value),placeholder:n,className:"w-full rounded-lg border border-[var(--border)] [background:var(--bg-card)] text-sm text-[var(--text-main)] placeholder:text-[var(--text-muted)] outline-none transition-[border-color,box-shadow] focus:border-primary focus:ring-2 focus:ring-primary/20",style:{height:kn(s),padding:kn(l)}})]})}function dc({value:e,onChange:r,options:n,placeholder:a,icon:s,className:l="",height:i=40,padding:c,iconLeft:d=10,searchable:u=!0}){const m=s?n.map((b,f)=>f===0&&!b.color?{...b,sublabel:b.sublabel??void 0}:b):n;return t.jsxs("div",{className:`relative ${l}`,children:[s&&t.jsx("span",{className:"pointer-events-none absolute top-1/2 z-10 -translate-y-1/2 text-[var(--text-muted)]",style:{left:kn(d)},children:s}),t.jsx(ar,{value:e,onChange:r,options:m,placeholder:a,searchable:u,minOptionsForSearch:5,height:i,padding:c??(s?"0 10px 0 30px":"0 10px"),className:"[&>button]:text-sm [&>button]:[background:var(--bg-card)]"})]})}const uc={sm:"24rem",md:"28rem",lg:"32rem",xl:"40rem","2xl":"48rem","4xl":"56rem","5xl":"64rem"},Sn=180,fc="bg-[color-mix(in_srgb,var(--bg-main)_72%,transparent)] backdrop-blur-sm";function Oa({open:e,onClose:r,title:n,subtitle:a,leadingIcon:s,headerActions:l,footer:i,children:c,size:d="md",maxWidth:u,zIndex:m=1e3,closeOnBackdrop:b=!0,closeOnEscape:f=!0,showCloseButton:g=!0,placement:v="center",bodyClassName:k="px-6 py-5",panelClassName:h="",backdropClassName:A=fc,contentClassName:$="p-4",ariaLabel:N,frameless:T=!1,disabled:x=!1}){const[y,L]=o.useState(!1),[w,W]=o.useState(!1),X=o.useRef(null);if(o.useEffect(()=>(e?(X.current&&clearTimeout(X.current),L(!0),requestAnimationFrame(()=>requestAnimationFrame(()=>W(!0)))):(W(!1),X.current=setTimeout(()=>L(!1),Sn+40)),()=>{X.current&&clearTimeout(X.current)}),[e]),o.useEffect(()=>{if(e)return document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}},[e]),o.useEffect(()=>{if(!e||!f)return;const te=ee=>{ee.key==="Escape"&&r()};return window.addEventListener("keydown",te),()=>window.removeEventListener("keydown",te)},[f,r,e]),!y)return null;const Z=n||a||s||l||g,D=u??uc[d],Q=v==="bottom-mobile"?"items-end sm:items-center justify-center p-0 sm:p-4":"items-center justify-center",j=v==="bottom-mobile"?"rounded-t-2xl sm:rounded-2xl":"rounded-2xl",se=w?"translateY(0) scale(1)":v==="bottom-mobile"?"translateY(16px) scale(0.98)":"translateY(10px) scale(0.96)";return ct.createPortal(t.jsxs("div",{role:"dialog","aria-modal":"true","data-bonsaif-overlay":"true","aria-label":N??n,className:`fixed inset-0 flex ${Q} ${$}`,style:{zIndex:m},children:[t.jsx("div",{className:`absolute inset-0 ${A}`,onClick:b?r:void 0,style:{opacity:w?1:0,transition:`opacity ${Sn}ms ease`}}),t.jsxs("div",{className:`relative z-10 flex max-h-[92dvh] w-full flex-col overflow-hidden ${T?"shadow-none":"shadow-2xl"} ${j} ${h}`,style:{maxWidth:D,background:T?"transparent":"var(--bg-card)",border:T?"none":"1px solid var(--border)",opacity:w?1:0,transform:se,transition:`opacity ${Sn}ms ease, transform ${Sn}ms ease`},onClick:te=>te.stopPropagation(),children:[x&&t.jsx("div",{className:"absolute inset-0 z-[1002] cursor-not-allowed rounded-2xl",style:{background:"color-mix(in srgb, var(--bg-card, #ffffff) 60%, transparent)",backdropFilter:"blur(2px)"}}),Z&&t.jsxs("div",{className:"flex flex-shrink-0 items-center justify-between gap-3 px-6 py-4",style:{borderBottom:"1px solid var(--border)"},children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[s&&t.jsx("div",{className:"flex-shrink-0",children:s}),(n||a)&&t.jsxs("div",{className:"min-w-0",children:[n&&t.jsx("h2",{className:"truncate text-base font-semibold",style:{color:"var(--text-main)"},children:n}),a&&t.jsx("p",{className:"truncate text-xs",style:{color:"var(--text-muted)"},children:a})]})]}),t.jsxs("div",{className:"flex flex-shrink-0 items-center gap-2",children:[l,g&&t.jsx(Ue,{variant:"icon",onClick:r,title:"Cerrar",children:t.jsx(q.HiXMark,{className:"h-5 w-5"})})]})]}),t.jsx("div",{className:`min-h-0 flex-1 overflow-y-auto ${k}`,children:c}),i&&t.jsx("div",{className:"flex flex-shrink-0 justify-end gap-2 px-6 py-4",style:{borderTop:"1px solid var(--border)"},children:i})]})]}),document.body)}const bc={danger:{iconBg:"rgba(239,68,68,0.12)",iconColor:"var(--danger)",btnBg:"var(--danger)",btnColor:"#fff"},warning:{iconBg:"rgba(245,158,11,0.12)",iconColor:"var(--warning)",btnBg:"var(--warning)",btnColor:"#fff"},primary:{iconBg:"rgba(59,130,246,0.12)",iconColor:"var(--primary)",btnBg:"var(--primary)",btnColor:"#fff"}};function mc({open:e,title:r,description:n,confirmLabel:a="Confirmar",cancelLabel:s="Cancelar",variant:l="danger",closeOnBackdrop:i=!0,onConfirm:c,onCancel:d}){const u=bc[l];return t.jsx(Oa,{open:e,onClose:d,size:"md",zIndex:9998,showCloseButton:!1,bodyClassName:"p-0",panelClassName:"overflow-visible",ariaLabel:r,closeOnBackdrop:i,children:t.jsxs("div",{className:"relative px-6 pb-6 pt-6",children:[t.jsx(Ue,{variant:"icon",onClick:d,className:"absolute right-3 top-3 h-8 w-8 hover:opacity-70",style:{color:"var(--text-muted)"},"aria-label":"Cancelar",children:t.jsx(q.HiXMark,{className:"h-4 w-4"})}),t.jsxs("div",{className:"flex gap-3 pr-8",children:[t.jsx("div",{className:"mt-0.5 flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-xl",style:{background:u.iconBg},children:t.jsx(q.HiExclamationTriangle,{className:"h-5 w-5",style:{color:u.iconColor}})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("h2",{className:"text-base font-semibold leading-snug",style:{color:"var(--text-main)"},children:r}),n?t.jsx("div",{className:"mt-1.5 text-sm leading-relaxed",style:{color:"var(--text-muted)"},children:n}):null]})]}),t.jsxs("div",{className:"mt-6 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[t.jsx(Ue,{variant:"secondary",onClick:d,className:"w-full sm:w-auto sm:min-w-[7.5rem]",style:{background:"var(--bg-input)"},children:s}),t.jsx(Ue,{variant:"danger",onClick:c,className:"w-full sm:w-auto sm:min-w-[7.5rem]",style:{background:u.btnBg,color:u.btnColor,borderColor:"transparent"},children:a})]})]})})}function pc(e){return e?typeof e=="function"?e():e:""}function hc(e){return/^https?:\/\//i.test(e)}function Ro(e,r){try{return new URL(e,r).toString()}catch{return e}}function gc(e,r,n,a=!1){const s=typeof e=="function"?e():e,l=r?r(s):s;if(!l||hc(l))return l;const i=pc(n);return i?Ro(l,i):a&&typeof window<"u"?Ro(l,window.location.origin):l}function vc({url:e,resolveUrl:r,baseUrl:n,useWindowOriginForRelative:a=!1,title:s="Copiar link",copiedTitle:l="Link copiado",icon:i=t.jsx(q.HiLink,{className:"h-3.5 w-3.5"}),...c}){return t.jsx(La,{...c,value:()=>gc(e,r,n,a),title:s,copiedTitle:l,icon:i})}const es=32767;function Cn(e){let r=String(e??"");return r=r.split("\0").join(""),r.length<=es?r:`${r.slice(0,es-1)}…`}const En=[25,50,100,200,500];let Nt={dataTable:{pageSizeOptions:[...En]}};function yc(){if(typeof window>"u")return;const r=window.__BONSAIF_DATA_TABLE_PREFERENCES_ENDPOINT__;return typeof r=="string"&&r.trim().length>0?r.trim().replace(/\/+$/,""):void 0}function Ha(){const e=Nt.dataTable.preferencesEndpoint,r=yc();return e&&e.trim().length>0?e.trim().replace(/\/+$/,""):r}function xc(e){if(!Array.isArray(e))return[...En];const r=Array.from(new Set(e.map(n=>typeof n=="number"?Math.floor(n):Number.NaN).filter(n=>Number.isFinite(n)&&n>0)));return r.length>0?r:[...En]}function ts(e){if(typeof e!="string")return;const r=e.trim();if(r)return r.replace(/\/+$/,"")}function wc(e){if(!e||typeof e!="object"||!e.dataTable)return;const r=ts(e.dataTable.preferencesEndpoint);Nt={...Nt,dataTable:{...Nt.dataTable,pageSizeOptions:xc(e.dataTable.pageSizeOptions),preferencesEndpoint:r??Nt.dataTable.preferencesEndpoint}}}function Nc(){return{dataTable:{pageSizeOptions:[...Nt.dataTable.pageSizeOptions]}}}function Xr(){return[...Nt.dataTable.pageSizeOptions]}function kc(){Nt={dataTable:{pageSizeOptions:[...En]}}}function Sc(e){Nt={...Nt,dataTable:{...Nt.dataTable,preferencesEndpoint:ts(e)}}}const Mn=[{value:"equals",label:"Igual a",valueMode:"single"},{value:"notEquals",label:"No es igual a",valueMode:"single"},{value:"greaterThan",label:"Mayor que",valueMode:"single"},{value:"greaterThanOrEqual",label:"Mayor o igual que",valueMode:"single"},{value:"lessThan",label:"Menor que",valueMode:"single"},{value:"lessThanOrEqual",label:"Menor o igual que",valueMode:"single"},{value:"between",label:"Entre",valueMode:"between"},{value:"top10",label:"10 superiores",valueMode:"none"},{value:"bottom10",label:"10 inferiores",valueMode:"none"},{value:"aboveAverage",label:"Sobre promedio",valueMode:"none"},{value:"belowAverage",label:"Bajo promedio",valueMode:"none"}],Cc=Mn.map(e=>({value:e.value,label:e.label})),Ec=12,Mc={layout:!0,filters:!1,sort:!1,bql:!1,pagination:!0},rs={layout:!0,filters:!0,sort:!0,bql:!0,pagination:!0},Tc="bonsaif-ui:datatable:",$c="[&_button]:h-7 [&_button]:min-h-0 [&_button]:gap-1 [&_button]:px-2 [&_button]:text-xs [&_button_svg]:h-3.5 [&_button_svg]:w-3.5 [&_button[data-icon=true]]:w-7 [&_button[data-icon=true]]:px-0",Ac=[],Lc=52;function _t(e){if(!e)return 150;const r=parseInt(e,10);return isNaN(r)||r<=0?150:r}function ns(e){return!!(e&&(Array.isArray(e.columnOrder)&&e.columnOrder.length>0||e.columnWidths&&Object.keys(e.columnWidths).length>0||Array.isArray(e.hiddenColumnKeys)&&e.hiddenColumnKeys.length>0||e.filters&&Object.keys(e.filters).length>0||e.conditionFilters&&Object.keys(e.conditionFilters).length>0||e.sort||typeof e.bql=="string"||Array.isArray(e.bqlHistory)&&e.bqlHistory.length>0||typeof e.pageSize=="number"))}function as(e){return`${Tc}${e}`}function Tn(e){try{const r=window.localStorage.getItem(as(e));if(!r)return null;const n=JSON.parse(r);return n&&typeof n=="object"?n:null}catch{return null}}function Dc(e,r){try{window.localStorage.setItem(as(e),JSON.stringify(r))}catch{}}function Ic(e,r){if(e===!0)return{...rs};if(e===!1)return{layout:!1,filters:!1,sort:!1,bql:!1,pagination:!1};if(r&&e==null)return{...rs};const n={...Mc,...e??{}};return r&&(typeof e!="object"||e.pagination!==!1)&&(n.pagination=!0),n}function os(...e){return e.reduce((r,n)=>({...r,...n??{}}),{})}function Ba(e,r,n){return typeof e!="number"||e<=0?n:Jr(r).includes(e)?e:n}function Kr(e){if(!e||typeof e!="object")return!1;const r=e;return typeof r.key=="string"&&(r.dir==="asc"||r.dir==="desc")}function Gr(e,r){if(!e||typeof e!="object"||Array.isArray(e))return{};const n=Object.entries(e).flatMap(([a,s])=>{if(!r.has(a)||!Array.isArray(s))return[];const l=s.filter(i=>typeof i=="string");return l.length>0?[[a,l]]:[]});return Object.fromEntries(n)}function Zr(e,r){if(!e||typeof e!="object"||Array.isArray(e))return{};const n=new Set(Mn.map(s=>s.value)),a=Object.entries(e).flatMap(([s,l])=>{if(!r.has(s)||!l||typeof l!="object")return[];const i=l;return!i.operator||!n.has(i.operator)?[]:[[s,{operator:i.operator,value:typeof i.value=="string"?i.value:"",valueTo:typeof i.valueTo=="string"?i.valueTo:""}]]});return Object.fromEntries(a)}function pt(e,r){if(or(e))return Lc;const n=e.minWidth??80,a=e.maxWidth??1/0;return Math.min(a,Math.max(n,r))}function Oc(e){const r=window.getComputedStyle(e);return parseFloat(r.paddingLeft)+parseFloat(r.paddingRight)}function or(e){return e.key==="actions"||e.key==="acciones"?!0:typeof e.header=="string"&&e.header.trim().toLowerCase()==="acciones"}function Fa(e){return e.sticky===!0}function ss(e){return!(e.reorderable===!1||e.sticky&&e.reorderable!==!0)}function Xt(e,r){const n=r.filter(Fa).map(i=>i.key);if(n.length===0)return e;const a=new Set(n),s=n.filter(i=>e.includes(i)),l=e.filter(i=>!a.has(i));return[...s,...l]}function Hc(e,r){if(r<=7)return Array.from({length:r},(a,s)=>s+1);const n=[1];e>3&&n.push("...");for(let a=Math.max(2,e-1);a<=Math.min(r-1,e+1);a++)n.push(a);return e<r-2&&n.push("..."),n.push(r),n}function Kt(e,r){var i;const n=new Set(r.filter(c=>c.hideable!==!1).map(c=>c.key)),a=Array.from(new Set(e??[])).filter(c=>n.has(c));if(r.filter(c=>!a.includes(c.key)).length>0)return a;const l=(i=r.find(c=>c.hideable!==!1))==null?void 0:i.key;return l?a.filter(c=>c!==l):[]}function Bc(e){return e==null||e===""?"(Vacio)":e instanceof Date?e.toLocaleDateString():String(e)}function gr(e){return e==null||typeof e=="boolean"?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(gr).join(" ").trim():o.isValidElement(e)?gr(e.props.children):""}function $n(e,r){const n=e.filterValue?e.filterValue(r):e.sortKey?r[e.sortKey]:e.cell(r);return typeof n=="string"||typeof n=="number"||typeof n=="boolean"||n===null||n===void 0||n instanceof Date?Bc(n):gr(n).trim()}function Qr(e){const r=e.replace(/,/g,"").trim();if(!r)return null;const n=Number(r);return Number.isFinite(n)?n:null}function vr(e,r){const n=Qr(e),a=Qr(r);return n!==null&&a!==null?n-a:e.localeCompare(r,void 0,{numeric:!0,sensitivity:"base"})}function Jr(e){const r=Array.from(new Set(e.map(n=>Math.floor(n)).filter(n=>Number.isFinite(n)&&n>0)));return r.length>0?r:Xr()}function Fc(e,r,n){var i,c;const a=((i=r.value)==null?void 0:i.trim())??"",s=((c=r.valueTo)==null?void 0:c.trim())??"",l=Mn.find(d=>d.value===r.operator);if((l==null?void 0:l.valueMode)==="single"&&!a||(l==null?void 0:l.valueMode)==="between"&&(!a||!s))return!0;switch(r.operator){case"equals":return e.toLowerCase()===a.toLowerCase();case"notEquals":return e.toLowerCase()!==a.toLowerCase();case"greaterThan":return vr(e,a)>0;case"greaterThanOrEqual":return vr(e,a)>=0;case"lessThan":return vr(e,a)<0;case"lessThanOrEqual":return vr(e,a)<=0;case"between":return vr(e,a)>=0&&vr(e,s)<=0;case"top10":case"bottom10":{const u=n.map(b=>({value:b,number:Qr(b)})).filter(b=>b.number!==null).sort((b,f)=>b.number-f.number).map(b=>b.value);return(r.operator==="top10"?u.slice(-10):u.slice(0,10)).includes(e)}case"aboveAverage":case"belowAverage":{const d=n.map(Qr).filter(b=>b!==null);if(d.length===0)return!1;const u=d.reduce((b,f)=>b+f,0)/d.length,m=Qr(e);return m===null?!1:r.operator==="aboveAverage"?m>u:m<u}default:return!0}}function ls({children:e,className:r="",style:n}){return t.jsx(Yt,{onlyWhenOverflow:!0,className:r,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",width:"100%",minWidth:0,...n},children:e})}function is({columns:e,data:r,getRowId:n,loading:a=!1,skeletonRows:s=8,emptyIcon:l,emptyText:i="Sin resultados",initialEmptyDelay:c=450,onRowClick:d,renderExpandedRow:u,getRowCanExpand:m,expandedRowIds:b,defaultExpandedRowIds:f=[],onExpandedRowIdsChange:g,expandOnRowClick:v=!1,selected:k,onToggleOne:h,onToggleAll:A,getRowSelectable:$,highlightSelected:N=!0,rowClassName:T,getRowCategory:x,stickyHeader:y=!0,pageSize:L=25,pageSizeOptions:w,pageSizeSelectWidth:W=62,pageSizeSelectHeight:X=30,pageSizeSelectPadding:Z="0 7px",totalRows:D,page:Q,onPageChange:j,onPageSizeChange:se,storageKey:te,stickyFirstColumn:ee=!1,bottomOffset:U=0,compact:J=!0,restrictHeight:ce=!0,maxHeight:C,minTableWidth:_,enableColumnVisibility:ae=!0,enableColumnFilters:B=!0,hiddenColumnKeys:I,defaultHiddenColumnKeys:E=Ac,onHiddenColumnKeysChange:oe,columnVisibilityLabel:K="Columnas",enableBql:Y=!1,bqlValue:S,defaultBqlValue:H="",onBqlChange:O,bqlDescription:re="Filtra registros con Bonsaif Query Language",bqlPlaceholder:z=`status = activo
2
+ rol IN (admin, employee)`,bqlQuickFilters:de=[],bqlExamples:he=[],bqlSuggestions:ie=[],bqlActiveFilters:ge,bqlError:Me,onQueryChange:$e,persistState:Dt,onPreferencesReady:ut,enableExport:Re=!1,exportFilename:It="datos",onExportCsv:Ct,onExportPdf:Et}){var $i;const le=Ic(Dt,te),Fe=Object.values(le).some(Boolean),ze=e.map(p=>p.key).join(","),ft=E.join(","),Ve=o.useRef(e),Mt=o.useRef(E);Ve.current=e,Mt.current=E;const[bt,rt]=o.useState(!te||!Fe),Wt=o.useRef(null),ue=o.useRef(!te),pe=o.useRef(!1),Le=o.useRef(ut);Le.current=ut;const He=o.useRef(!te||!Fe?te??"__none__":null),Ie=I!==void 0,[tt,at]=o.useState(()=>Kt(E,e)),We=Kt(Ie?I:tt,e),[Ke,Ge]=o.useState(!1),[Ae,lr]=o.useState("filter"),[ir,Or]=o.useState(null),[Jt,oa]=o.useState(""),[lt,jt]=o.useState({}),[F,G]=o.useState({}),fe=b!==void 0,[be,Te]=o.useState(f),ye=S!==void 0,[Be,De]=o.useState(H),Ye=ye?S:Be,[Ze,Ot]=o.useState(Ye),[ot,it]=o.useState(!1),[cr,qt]=o.useState(!1),[fn,Hr]=o.useState(!1),[bn,Br]=o.useState([]),Fr=o.useRef(null),dr=o.useRef(null),Ht=o.useRef(O);Ht.current=O;const sa=o.useRef(L);sa.current=L;const la=o.useRef(w);la.current=w;const Sb=Array.isArray(w)?w.join(","):"",No=o.useRef(null),Rl=o.useRef(null),ko=o.useRef(null),ei=o.useRef(0),[Cb,Eb]=o.useState({}),[Mb,Tb]=o.useState({}),[mn,ia]=o.useState(!1),So=o.useRef(null),ca=o.useRef(null),[$b,Ab]=o.useState({}),ti=o.useRef(null),da=o.useRef(null),[Co,ri]=o.useState(r.length>0||a||c===!1),ni=(p,M)=>50+(p*17+M*13+7)%40,Rt=o.useRef(null),[Lb,Db]=o.useState(void 0),[ai,Ib]=o.useState(0),[Ob,Hb]=o.useState(!1);o.useEffect(()=>{function p(){Hb(window.innerWidth<640)}if(!ce||C!==void 0)return p(),window.addEventListener("resize",p),()=>window.removeEventListener("resize",p);const R=L!==!1?48:0,P=12;function ne(){if(p(),!Rt.current)return;const me=Rt.current.getBoundingClientRect().top;Db(Math.max(120,window.innerHeight-me-R-P-U))}return ne(),window.addEventListener("resize",ne),()=>window.removeEventListener("resize",ne)},[a,L,U,ce,C]);const oi=ce?C??Lb:void 0;o.useEffect(()=>{const p=Rt.current;if(!p)return;const M=()=>Ib(p.clientWidth);if(M(),typeof ResizeObserver>"u")return window.addEventListener("resize",M),()=>window.removeEventListener("resize",M);const R=new ResizeObserver(M);return R.observe(p),()=>R.disconnect()},[a,bt,r.length]),o.useEffect(()=>{if(c===!1||a||r.length>0){ri(!0);return}if(Co)return;const p=window.setTimeout(()=>{ri(!0)},c);return()=>window.clearTimeout(p)},[r.length,c,Co,a]);const[Pr,_r]=o.useState(()=>Xt(e.map(p=>p.key),e)),[ur,zr]=o.useState(()=>Object.fromEntries(e.map(p=>[p.key,pt(p,_t(p.width))]))),[Xe,fr]=o.useState(null),[Bb,ua]=o.useState(1),[fa,ba]=o.useState(L===!1?0:L);o.useEffect(()=>{var Ee;const p=Ve.current,M=Mt.current,R=p.map(Ne=>Ne.key),P=new Set(R),ne=()=>{var Ne;pe.current||(pe.current=!0,(Ne=Le.current)==null||Ne.call(Le))};if(!te||!Fe){le.layout&&_r(Xt(R,p)),Ie||at(Kt(M,p)),ue.current=!1,rt(!0),ne();return}let me=!1;const ke=He.current===te;ke||(ue.current=!1,rt(!1),pe.current=!1);const Ce=Tn(te);if(ns(Ce)&&!ke){const Ne=Ce,xe=Jr(la.current??Xr()),we=sa.current,pr=we===!1?0:we,tr=le.layout?Ne==null?void 0:Ne.columnOrder:void 0,rr=Array.isArray(tr)?tr.filter(_e=>R.includes(_e)):[],nr=R.filter(_e=>!rr.includes(_e)),hr=Xt(rr.length>0?[...rr,...nr]:R,p),qr=Object.fromEntries(p.map(_e=>[_e.key,pt(_e,_t(_e.width))])),Ur=le.layout?(Ne==null?void 0:Ne.columnWidths)??{}:{},vn=Object.fromEntries(p.map(_e=>[_e.key,pt(_e,Ur[_e.key]??qr[_e.key])])),Vr=Kt(le.layout?(Ne==null?void 0:Ne.hiddenColumnKeys)??M:M,p);if(le.layout&&(_r(hr),zr(vn)),Ie||at(Vr),le.filters&&(jt(Gr(Ne==null?void 0:Ne.filters,P)),G(Zr(Ne==null?void 0:Ne.conditionFilters,P))),le.sort){const _e=Kr(Ne==null?void 0:Ne.sort)?Ne.sort:null;fr(_e&&P.has(_e.key)?_e:null)}if(le.bql){if(Fr.current!==te){Fr.current=te;const _e=typeof(Ne==null?void 0:Ne.bql)=="string"?Ne.bql:H;ye?(Ee=Ht.current)==null||Ee.call(Ht,_e):De(_e)}Br(Array.isArray(Ne==null?void 0:Ne.bqlHistory)?Ne.bqlHistory.filter(_e=>typeof _e=="string"):[])}le.pagination&&dr.current!==te&&(dr.current=te,ba(Ba(Ne==null?void 0:Ne.pageSize,xe,pr))),He.current=te,rt(!0),ne()}const mt=`${Ha()??"/api/user/preferences/datatables"}?key=${encodeURIComponent(te)}`,et=new AbortController,ve=window.setTimeout(()=>et.abort(),2500);return fetch(mt,{cache:"no-store",signal:et.signal}).then(Ne=>Ne.ok?Ne.json():null).then(Ne=>{var Ai;if(me)return;const xe=Tn(te),we=os(ns(Ne==null?void 0:Ne.settings)?Ne==null?void 0:Ne.settings:null,xe),pr=Jr(la.current??Xr()),tr=sa.current,rr=tr===!1?0:tr,nr=le.layout?we==null?void 0:we.columnOrder:void 0,hr=Array.isArray(nr)?nr.filter(Qe=>R.includes(Qe)):[],qr=R.filter(Qe=>!hr.includes(Qe)),Ur=Xt(hr.length>0?[...hr,...qr]:R,p),vn=Object.fromEntries(p.map(Qe=>[Qe.key,pt(Qe,_t(Qe.width))])),Vr=le.layout?(we==null?void 0:we.columnWidths)??{}:{},_e=Object.fromEntries(p.map(Qe=>[Qe.key,pt(Qe,Vr[Qe.key]??vn[Qe.key])])),Yr=Kt(le.layout?(we==null?void 0:we.hiddenColumnKeys)??M:M,p);if(le.layout&&(_r(Ur),zr(_e)),Ie||at(Yr),le.filters&&(jt(Gr(we==null?void 0:we.filters,P)),G(Zr(we==null?void 0:we.conditionFilters,P))),le.sort){const Qe=Kr(we==null?void 0:we.sort)?we.sort:null;fr(Qe&&P.has(Qe.key)?Qe:null)}if(le.bql){if(Fr.current!==te){Fr.current=te;const Qe=typeof(we==null?void 0:we.bql)=="string"?we.bql:H;ye?(Ai=Ht.current)==null||Ai.call(Ht,Qe):De(Qe)}Br(Array.isArray(we==null?void 0:we.bqlHistory)?we.bqlHistory.filter(Qe=>typeof Qe=="string"):[])}let je;le.pagination&&(je=Ba(we==null?void 0:we.pageSize,pr,rr),dr.current!==te&&(dr.current=te,ba(je))),Wt.current=JSON.stringify({columnOrder:Ur,columnWidths:_e,hiddenColumnKeys:Yr,filters:Gr(we==null?void 0:we.filters,P),conditionFilters:Zr(we==null?void 0:we.conditionFilters,P),sort:Kr(we==null?void 0:we.sort)?we.sort:null,bql:typeof(we==null?void 0:we.bql)=="string"?we.bql:"",bqlHistory:Array.isArray(we==null?void 0:we.bqlHistory)?we.bqlHistory:[],pageSize:le.pagination&&tr!==!1?je:void 0}),ue.current=!0}).catch(()=>{var Ne;if(!me){const xe=Tn(te),we=Jr(la.current??Xr()),pr=sa.current,tr=pr===!1?0:pr,rr=le.layout?xe==null?void 0:xe.columnOrder:void 0,nr=Array.isArray(rr)?rr.filter(je=>R.includes(je)):[],hr=R.filter(je=>!nr.includes(je)),qr=Xt(nr.length>0?[...nr,...hr]:R,p),Ur=Object.fromEntries(p.map(je=>[je.key,pt(je,_t(je.width))])),vn=le.layout?(xe==null?void 0:xe.columnWidths)??{}:{},Vr=Object.fromEntries(p.map(je=>[je.key,pt(je,vn[je.key]??Ur[je.key])]));le.layout&&(_r(qr),zr(Vr));const _e=Kt(le.layout?(xe==null?void 0:xe.hiddenColumnKeys)??M:M,p);if(Ie||at(_e),le.filters&&(jt(Gr(xe==null?void 0:xe.filters,P)),G(Zr(xe==null?void 0:xe.conditionFilters,P))),le.sort){const je=Kr(xe==null?void 0:xe.sort)?xe.sort:null;fr(je&&P.has(je.key)?je:null)}if(le.bql){if(Fr.current!==te){Fr.current=te;const je=typeof(xe==null?void 0:xe.bql)=="string"?xe.bql:H;ye?(Ne=Ht.current)==null||Ne.call(Ht,je):De(je)}Br(Array.isArray(xe==null?void 0:xe.bqlHistory)?xe.bqlHistory.filter(je=>typeof je=="string"):[])}let Yr;le.pagination&&(Yr=Ba(xe==null?void 0:xe.pageSize,we,tr),dr.current!==te&&(dr.current=te,ba(Yr))),Wt.current=JSON.stringify({columnOrder:qr,columnWidths:Vr,hiddenColumnKeys:_e,filters:Gr(xe==null?void 0:xe.filters,P),conditionFilters:Zr(xe==null?void 0:xe.conditionFilters,P),sort:Kr(xe==null?void 0:xe.sort)?xe.sort:null,bql:typeof(xe==null?void 0:xe.bql)=="string"?xe.bql:"",bqlHistory:Array.isArray(xe==null?void 0:xe.bqlHistory)?xe.bqlHistory:[],pageSize:le.pagination&&pr!==!1?Yr:void 0}),ue.current=!0}}).finally(()=>{window.clearTimeout(ve),me||(He.current=te,rt(!0),ne())}),()=>{me=!0,et.abort(),window.clearTimeout(ve)}},[te,Fe,ze,ft,Ie,le.layout,le.filters,le.sort,le.bql,le.pagination,ye,H,Sb]),o.useEffect(()=>{if(!te||!bt||!Fe||!ue.current)return;const p={};le.layout&&(p.columnOrder=Pr,p.columnWidths=ur,p.hiddenColumnKeys=We),le.filters&&(p.filters=lt,p.conditionFilters=F),le.sort&&(p.sort=Xe),le.bql&&(p.bql=Ye,p.bqlHistory=bn),le.pagination&&L!==!1&&(p.pageSize=fa);const M=Tn(te),R=os(M,p),P=JSON.stringify(R);if(P===Wt.current)return;Dc(te,R),Wt.current=P;const ne=window.setTimeout(()=>{const me=Ha()??"/api/user/preferences/datatables";fetch(me,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:te,settings:R})}).then(()=>{}).catch(()=>{})},300);return()=>window.clearTimeout(ne)},[Pr,ur,We,lt,F,Xe,Ye,bn,fa,L,te,bt,Fe,le.layout,le.filters,le.sort,le.bql,le.pagination]),o.useEffect(()=>{_r(p=>{const M=e.map(ne=>ne.key),R=p.filter(ne=>M.includes(ne)),P=M.filter(ne=>!R.includes(ne));return Xt([...R,...P],e)})},[ze,e]);const si=Xt(Pr,e).map(p=>e.find(M=>M.key===p)).filter(p=>!!p),wt=si.filter(p=>!We.includes(p.key)),li=e.some(Fa),Fb=Object.keys(lt).length,Pb=Object.keys(F).length,Eo=Fb+Pb;function ii(p){const M=new Set;return r.reduce((R,P)=>{const ne=$n(p,P);return!ne||M.has(ne)||(M.add(ne),R.push({value:ne,label:ne})),R},[])}function _b(){const p=e.find(M=>M.key===ir);return p?ii(p):[]}function zb(p){return!!(B&&!or(p)&&(p.filterValue||p.sortKey||ii(p).length>0))}function ci(p,M){jt(R=>{const P={...R};return P[p]=M,P})}function Wb(p,M,R,P){const ne=lt[p]??[],me=P?ne:R.filter(Ce=>Ce!==M),ke=P?ne.includes(M)?ne.filter(Ce=>Ce!==M):[...ne,M]:me;ke.length===R.length?Mo(p):ci(p,ke)}function Mo(p){jt(M=>{const R={...M};return delete R[p],R})}function ma(p,M){G(R=>{const P={...R};return M?P[p]=M:delete P[p],P})}function di(p){ma(p,null)}function jb(){jt({}),G({})}function qb(p){ye||De(p),O==null||O(p)}function ui(p){const M=p.trim();Ot(M),(O==null?void 0:O(M))!==!1&&(ye||De(M),it(!1),qt(!1),Hr(!1),M&&Br(P=>[M,...P.filter(ne=>ne!==M)].slice(0,Ec)))}function fi(){Ot(""),qb(""),it(!1),qt(!1),Hr(!1)}function To(p,M){Ot(p),M&&(M.style.height="auto",M.style.height=`${Math.min(M.scrollHeight,180)}px`)}function pa(p){const M=p.trim();if(!M)return;ei.current=Date.now()+500;const R=Ze.replace(/\s+$/u,""),P=R.length===0?M:R.split(`
3
+ `).map(ne=>ne.trim()).includes(M)?R:`${R}
4
+ ${M}`;To(P,ko.current??void 0),requestAnimationFrame(()=>{const ne=ko.current;if(!ne)return;ne.focus();const me=ne.value.length;ne.setSelectionRange(me,me),To(ne.value,ne)})}o.useEffect(()=>{Ot(Ye)},[Ye]);const ha=o.useCallback(()=>{const p=No.current;if(!p)return;const M=p.getBoundingClientRect(),R=12,P=8,ne=Math.min(780,Math.max(320,window.innerWidth-32)),me=Math.max(R,window.innerWidth-ne-R),ke=Math.min(Math.max(R,M.left),me),Ce=M.bottom+P,Pe=window.innerHeight-M.top+P,qe=window.innerHeight-Ce-R,mt=M.top-R-P,et=qe<280&&mt>qe,ve=Math.max(240,et?mt:qe);Eb({position:"fixed",zIndex:1e4,left:ke,top:et?void 0:Ce,bottom:et?Pe:void 0,width:ne,maxWidth:"calc(100vw - 24px)",maxHeight:ve,overflowY:"auto"})},[]);o.useEffect(()=>{if(!ot)return;function p(P){var me,ke;if(Date.now()<ei.current)return;const ne=P.target;(me=No.current)!=null&&me.contains(ne)||(ke=Rl.current)!=null&&ke.contains(ne)||(it(!1),qt(!1),Hr(!1))}function M(P){P.key==="Escape"&&(it(!1),qt(!1),Hr(!1))}function R(){ha()}return ha(),document.addEventListener("mousedown",p),window.addEventListener("keydown",M),window.addEventListener("resize",R),window.addEventListener("scroll",R,!0),()=>{document.removeEventListener("mousedown",p),window.removeEventListener("keydown",M),window.removeEventListener("resize",R),window.removeEventListener("scroll",R,!0)}},[ot,ha]);function bi(p){const M=Kt(p,e);Ie||at(M),oe==null||oe(M)}function Ub(p){bi(We.includes(p)?We.filter(M=>M!==p):[...We,p])}function Vb(){bi([])}const $o=o.useCallback((p=da.current)=>{if(!p)return;const M=p.getBoundingClientRect(),R=Math.min(292,Math.max(240,window.innerWidth-16)),P=Math.max(8,window.innerWidth-R-8),ne=Math.min(Math.max(8,M.right-R),P),me=window.innerHeight-M.bottom,ke=M.bottom+6,Ce=window.innerHeight-M.top+6,qe=me<360&&M.top>me?void 0:ke,mt=qe===void 0?Ce:void 0,et=Math.max(220,qe===void 0?M.top-16:window.innerHeight-ke-8),ve={position:"fixed",zIndex:9999,left:ne,top:qe,bottom:mt,width:R,maxWidth:"calc(100vw - 16px)",maxHeight:et,"--dt-column-menu-max-height":`${et}px`};Tb(ve)},[]);function mi(p,M,R=null){p.preventDefault(),p.stopPropagation();const P=da.current===p.currentTarget&&Ae===M&&ir===R;if(Ke&&P){Ge(!1),Or(null);return}da.current=p.currentTarget,lr(M),Or(R),oa(""),$o(p.currentTarget),Ge(!0)}function Yb(p){if(or(p))return;const M=Rt.current;if(!M)return;const P=Array.from(M.querySelectorAll("[data-dt-column-key]")).filter(ne=>ne.dataset.dtColumnKey===p.key).reduce((ne,me)=>{const ke=me.querySelector("[data-dt-autofit-content]"),Ce=ke?ke.scrollWidth:Math.max(me.scrollWidth,me.offsetWidth);return Math.max(ne,Math.ceil(Ce+Oc(me)))},0);P<=0||zr(ne=>({...ne,[p.key]:pt(p,P+12)}))}o.useEffect(()=>{zr(p=>{const M=Object.fromEntries(e.map(R=>[R.key,pt(R,_t(R.width))]));return Object.fromEntries(e.map(R=>[R.key,pt(R,p[R.key]??M[R.key])]))})},[ze,e]),o.useEffect(()=>{Ie||at(p=>Kt(p,e))},[ze,e,Ie]),o.useEffect(()=>{function p(P){var ke,Ce;const ne=P.target,me=P.target;me!=null&&me.closest("[data-bonsaif-select-dropdown='true']")||!((ke=ti.current)!=null&&ke.contains(ne))&&!((Ce=da.current)!=null&&Ce.contains(ne))&&(Ge(!1),Or(null))}function M(P){P.key==="Escape"&&(Ge(!1),Or(null))}function R(){$o()}return Ke&&(document.addEventListener("mousedown",p),window.addEventListener("keydown",M),window.addEventListener("resize",R),window.addEventListener("scroll",R,!0)),()=>{document.removeEventListener("mousedown",p),window.removeEventListener("keydown",M),window.removeEventListener("resize",R),window.removeEventListener("scroll",R,!0)}},[Ke,$o]);const pn=o.useRef(null);o.useEffect(()=>{function p(R){const P=pn.current;if(!P)return;const ne=R.clientX-P.startX,me=e.find(ke=>ke.key===P.colKey);me&&zr(ke=>({...ke,[P.colKey]:pt(me,P.startWidth+ne)}))}function M(){pn.current&&(pn.current=null,document.body.style.cursor="",document.body.style.userSelect="")}return document.addEventListener("pointermove",p),document.addEventListener("pointerup",M),()=>{document.removeEventListener("pointermove",p),document.removeEventListener("pointerup",M)}},[e]);const hn=o.useRef(null),[pi,Ao]=o.useState(null);function Xb(p,M){const R=e.find(P=>P.key===p);if(!R||!ss(R)){M.preventDefault();return}hn.current=Pr.indexOf(p),M.dataTransfer.effectAllowed="move"}function Kb(p,M){M.preventDefault(),M.dataTransfer.dropEffect="move";const R=Pr.indexOf(p);pi!==R&&Ao(R)}function Gb(p,M){M.preventDefault();const R=hn.current,P=Pr.indexOf(p);R!==null&&R!==P&&_r(ne=>{const me=[...ne],[ke]=me.splice(R,1);return me.splice(P,0,ke),Xt(me,e)}),hn.current=null,Ao(null)}function Zb(){hn.current=null,Ao(null)}function Qb(p){p.sortKey&&fr(M=>(M==null?void 0:M.key)===p.key?{key:p.key,dir:M.dir==="asc"?"desc":"asc"}:{key:p.key,dir:"asc"})}o.useEffect(()=>{ua(1)},[r]),o.useEffect(()=>{ua(1)},[F,lt]);const Bt=!!(j&&se),er=L!==!1,Lo=o.useMemo(()=>Jr(w??Xr()),[w]),st=Bt?Q??1:Bb,hi=er&&fa<1?typeof L=="number"&&L>0?L:Lo[0]??25:fa,Ft=Bt||er?hi:r.length,Tt=!!k&&!!h&&!!A,Do=o.useMemo(()=>$?r.filter(p=>$(p)):r,[r,$]),Wr=!!u,gi=o.useMemo(()=>new Set(fe?Array.from(b??[]):be),[fe,b,be]),Jb=(Wr?40:0)+(Tt?40:0),Io=!Ob&&(li||ee),ga=(()=>{if(!Io)return{};let p=Jb;const M={};return wt.forEach((R,P)=>{(Fa(R)||!li&&ee&&P===0)&&(M[R.key]=p,p+=ur[R.key]??pt(R,_t(R.width)))}),M})(),Oo=Object.keys(ga),Ho=Oo.length>0?Oo[Oo.length-1]:null,vi=Tt&&Do.length>0&&Do.every(p=>k.has(n(p))),Rb=Tt&&k.size>0&&Do.some(p=>k.has(n(p)))&&!vi,va=o.useMemo(()=>{if(Bt)return r;const p=Object.entries(lt),M=Object.entries(F);return p.length===0&&M.length===0?r:r.filter(R=>p.every(([P,ne])=>{const me=e.find(ke=>ke.key===P);return me?ne.includes($n(me,R)):!0})&&M.every(([P,ne])=>{const me=e.find(Ce=>Ce.key===P);if(!me)return!0;const ke=r.map(Ce=>$n(me,Ce));return Fc($n(me,R),ne,ke)}))},[F,lt,e,r,Bt]),br=o.useMemo(()=>{if(!Xe)return va;const p=e.find(M=>M.key===Xe.key&&M.sortKey);return p!=null&&p.sortKey?[...va].sort((M,R)=>{const P=M[p.sortKey],ne=R[p.sortKey],me=P===ne?0:P==null?1:ne==null||P<ne?-1:1;return Xe.dir==="asc"?me:-me}):va},[va,Xe,e]),yi=o.useMemo(()=>{if(Bt||!er)return br;const p=(st-1)*Ft;return br.slice(p,p+Ft)},[br,Bt,er,st,Ft]),Ut=Bt?D??r.length:br.length,Bo=er?Math.max(1,Math.ceil(Ut/Ft)):1,em=Math.min(...Lo),tm=er&&(Ut>Ft||Ut>em),rm=er?(st-1)*Ft+1:1,nm=er?Math.min(st*Ft,Ut):Ut;function Fo(p){if(a)return;const M=Math.max(1,Math.min(p,Bo));Bt?j(M):ua(M)}function am(p){a||(te&&(dr.current=te),ba(p),Bt?(se(p),j(1)):(ua(1),se==null||se(p)))}function xi(p){const M=new Set(gi);M.has(p)?M.delete(p):M.add(p);const R=Array.from(M);fe||Te(R),g==null||g(R)}o.useEffect(()=>{$e==null||$e({bql:Ye,filters:lt,conditionFilters:F,sort:Xe,page:st,pageSize:Ft,hiddenColumnKeys:We})},[Ye,lt,F,Xe,st,Ft,We,$e]);const wi=p=>p==="center"?"justify-center text-center":p==="right"?"justify-end text-right":"justify-start text-left",om="color-mix(in srgb, var(--primary) 6%, var(--bg-card))",Po="linear-gradient(180deg, color-mix(in srgb, var(--bg-input) 90%, var(--bg-card)) 0%, color-mix(in srgb, var(--bg-input) 70%, var(--bg-card)) 100%)",Oe="color-mix(in srgb, var(--border) 62%, var(--bg-card))",mr="color-mix(in srgb, var(--primary) 24%, var(--border))",ya=`inset 0 0 0 1px ${Oe}`,Ni=wt.reduce((p,M)=>p+(ur[M.key]??_t(M.width)),(Wr?40:0)+(Tt?40:0)),ki=typeof _=="number"?_:typeof _=="string"?Number((($i=_.match(/^(\d+(?:\.\d+)?)px$/))==null?void 0:$i[1])??NaN):NaN,gn=Number.isFinite(ki)?Math.max(Ni,ki,ai):Math.max(Ni,ai),xa=_??gn,jr=`${Wr?"40px ":""}${Tt?"40px ":""}${wt.map(p=>`${ur[p.key]??_t(p.width)}px`).join(" ")}`;o.useEffect(()=>{Xe&&We.includes(Xe.key)&&fr(null)},[We,Xe]);function Si(p){return p?typeof p=="string"?{key:p,label:p}:p:null}const wa=()=>t.jsxs("div",{role:"row",className:"grid",style:{gridTemplateColumns:jr,background:Po,borderBottom:`1px solid ${mr}`},children:[Wr&&t.jsx("div",{role:"columnheader",className:`${J?"px-2 py-1.5":"px-3 py-2.5"} w-10`,style:{borderBottom:`1px solid ${mr}`,borderRight:`1px solid ${Oe}`}}),Tt&&t.jsx("div",{role:"columnheader",className:`${J?"px-2 py-1.5":"px-3 py-2.5"} flex w-10 items-center justify-center`,style:Io?{position:"sticky",left:0,zIndex:12,background:Po,backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)",boxShadow:`inset 0 -1px 0 ${mr}`,borderRight:`1px solid ${Oe}`}:{borderBottom:`1px solid ${mr}`,borderRight:`1px solid ${Oe}`},children:t.jsx(Nn,{size:"sm",checked:vi,indeterminate:Rb,onChange:A,"aria-label":"Seleccionar todos",containerClassName:"items-center",className:"cursor-pointer"})}),wt.map((p,M)=>{const R=(Xe==null?void 0:Xe.key)===p.key,P=!!p.sortKey,ne=or(p),me=ga[p.key],ke=me!==void 0,Ce=p.key===Ho,Pe=ss(p),qe=pi===M,et=(ur[p.key]??_t(p.width))<120,ve=Object.prototype.hasOwnProperty.call(lt,p.key)||Object.prototype.hasOwnProperty.call(F,p.key);return t.jsxs("div",{role:"columnheader","data-dt-column-key":p.key,className:`group select-none ${et?"text-left":wi(p.align)}`,style:{...ke?{position:"sticky",left:me,zIndex:12,background:Po,backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)",boxShadow:Ce?`3px 0 6px -2px rgba(0,0,0,0.10), inset 0 -1px 0 ${mr}`:`inset 0 -1px 0 ${mr}`,borderRight:`1px solid ${Oe}`}:{position:"relative",borderBottom:`1px solid ${mr}`,borderRight:`1px solid ${Oe}`},color:R?"var(--primary)":"var(--text-muted)",whiteSpace:"nowrap",transition:"color 0.15s",borderLeft:qe?"2px solid var(--primary)":"2px solid transparent",cursor:"default",padding:ne?J?"7px 6px":"9px 8px":J?"8px 6px 10px":"10px 8px 12px"},onDragOver:Ee=>{(Pe||hn.current!==null)&&Kb(p.key,Ee)},onDrop:Ee=>Gb(p.key,Ee),children:[t.jsxs("div",{className:`flex min-w-0 items-center gap-1 ${ne?"justify-center":et?"justify-start":p.align==="center"?"justify-center":p.align==="right"?"justify-end":"justify-start"}`,children:[Pe?t.jsx("span",{draggable:!0,onDragStart:Ee=>{Ee.stopPropagation(),Xb(p.key,Ee)},onDragEnd:Ee=>{Ee.stopPropagation(),Zb()},onClick:Ee=>Ee.stopPropagation(),title:"Arrastrar para mover columna","aria-label":"Arrastrar para mover columna",className:`absolute left-0 top-0 z-10 inline-flex h-full w-3 shrink-0 rounded-sm transition-colors duration-150 hover:bg-[var(--primary)]/15 ${qe?"bg-[var(--primary)]/20":""}`,style:{cursor:"grab"}}):null,ne?t.jsx("span",{className:"inline-flex h-5 w-5 items-center justify-center rounded-md text-[var(--text-muted)]",title:"Acciones","aria-label":"Acciones",children:t.jsx(q.HiCog6Tooth,{className:"h-3.5 w-3.5"})}):t.jsx(ls,{className:"min-w-0 flex-1",children:t.jsx("span",{"data-dt-autofit-content":!0,className:`inline-flex max-w-full items-center font-semibold uppercase tracking-wider ${J?"text-[11px]":"text-xs"}`,children:t.jsx("span",{className:"min-w-0 truncate",children:p.header})})}),P&&t.jsx("button",{type:"button","aria-label":`Ordenar por ${String(p.header)}`,title:"Ordenar",onClick:Ee=>{Ee.stopPropagation(),Qb(p)},"data-dt-sort-button":!0,className:`absolute -bottom-2 left-1/2 z-20 inline-flex h-4 w-4 -translate-x-1/2 items-center justify-center rounded-full bg-[var(--primary)] text-[var(--primary-fg)] shadow-[0_1px_3px_rgba(15,23,42,0.22)] transition-[opacity,transform] duration-150 hover:scale-105 focus:scale-105 focus:opacity-100 focus:outline-none ${R?"opacity-100":"opacity-0 group-hover:opacity-100 group-focus-within:opacity-100"}`,style:{bottom:"-0.5rem",top:"auto"},children:R?Xe.dir==="asc"?t.jsx(q.HiChevronUp,{className:"h-3 w-3"}):t.jsx(q.HiChevronDown,{className:"h-3 w-3"}):t.jsx(q.HiChevronUpDown,{className:"h-3 w-3"})}),B&&!ne&&zb(p)&&t.jsx("button",{type:"button","aria-haspopup":"menu","aria-expanded":Ke&&ir===p.key,"aria-label":`Filtrar ${String(p.header)}`,title:"Filtrar",onClick:Ee=>mi(Ee,"filter",p.key),className:`inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-sm bg-transparent text-[var(--text-muted)] opacity-0 transition-[opacity,color,background-color] duration-150 hover:bg-[var(--bg-card)] hover:text-[var(--primary)] focus:bg-[var(--bg-card)] focus:text-[var(--primary)] focus:opacity-100 group-hover:opacity-100 ${Ke&&Ae==="filter"&&ir===p.key?"bg-[var(--bg-card)] text-[var(--primary)] opacity-100":ve?"text-[var(--primary)] opacity-100":""}`,children:ve?t.jsx(q.HiFunnel,{className:"h-3.5 w-3.5"}):t.jsx(q.HiEllipsisVertical,{className:"h-3.5 w-3.5"})})]}),!ne&&t.jsx("span",{role:"separator","aria-orientation":"vertical",title:"Arrastrar para redimensionar. Doble click para autoajustar",onPointerDown:Ee=>{Ee.preventDefault(),Ee.stopPropagation(),pn.current={colKey:p.key,startX:Ee.clientX,startWidth:ur[p.key]??150},document.body.style.cursor="col-resize",document.body.style.userSelect="none"},onDoubleClick:Ee=>{Ee.preventDefault(),Ee.stopPropagation(),pn.current=null,document.body.style.cursor="",document.body.style.userSelect="",Yb(p)},onClick:Ee=>Ee.stopPropagation(),className:"absolute top-0 flex h-full items-center justify-center opacity-0 transition-opacity duration-200 hover:opacity-100",style:{right:0,width:12,cursor:"col-resize",zIndex:6,transform:"translateX(50%)"},children:t.jsxs("span",{style:{display:"flex",gap:4,alignItems:"center",height:"calc(100% - 8px)"},children:[t.jsx("span",{style:{width:2,height:"100%",borderRadius:2,background:"var(--primary)",display:"block"}}),t.jsx("span",{style:{width:2,height:"100%",borderRadius:2,background:"var(--primary)",display:"block"}})]})})]},p.key)})]}),Na=()=>{if(!Ke||typeof document>"u"||Ae==="visibility"&&!ae||Ae==="filter"&&!B)return null;const p=e.find(ve=>ve.key===ir),M=_b(),R=p?Object.prototype.hasOwnProperty.call(lt,p.key):!1,P=p?F[p.key]:void 0,ne=Mn.find(ve=>ve.value===(P==null?void 0:P.operator)),me=p?lt[p.key]??[]:[],ke=Jt.trim().toLowerCase(),Ce=ke?M.filter(ve=>ve.label.toLowerCase().includes(ke)):M,Pe=p&&M.length>0&&(!R||me.length===M.length),qe=p&&R&&me.length>0&&me.length<M.length,mt=We.length,et=()=>{p&&(Mo(p.key),di(p.key))};return ct.createPortal(t.jsx("div",{ref:ti,role:"menu",className:"overflow-hidden rounded-lg border p-1 shadow-xl",style:{...Mb,borderColor:"var(--border)",background:"var(--bg-card)"},children:Ae==="visibility"?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-[var(--border)] px-2 py-1.5",children:[t.jsx("span",{className:"min-w-0 truncate text-xs font-semibold uppercase text-[var(--text-muted)]",children:mt>0?`${wt.length} de ${e.length} visibles`:`${e.length} visibles`}),t.jsx("button",{type:"button",onClick:Vb,disabled:mt===0,className:"rounded px-1.5 py-0.5 text-xs font-medium text-[var(--primary)] transition-colors hover:bg-[var(--bg-input)] disabled:opacity-40",children:"Mostrar todas"})]}),t.jsx("div",{className:"max-h-72 overflow-auto py-1",children:si.map(ve=>{const Ee=!We.includes(ve.key),xe=!(ve.hideable!==!1)||Ee&&wt.length<=1;return t.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":Ee,disabled:xe,onClick:()=>Ub(ve.key),className:"flex w-full min-w-0 items-center gap-2 rounded-md px-2.5 py-1.5 text-left transition-colors hover:bg-[var(--bg-input)] disabled:cursor-not-allowed disabled:opacity-50",style:{color:"var(--text-main)"},children:[t.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center rounded border",style:{borderColor:Ee?"var(--primary)":"var(--border)",background:Ee?"var(--primary)":"var(--bg-input)",color:"var(--primary-fg)"},children:Ee&&t.jsx(q.HiCheck,{className:"h-3 w-3"})}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:ve.header})]},ve.key)})})]}):p?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-[var(--border)] px-2 py-1.5",children:[t.jsxs("span",{className:"min-w-0 truncate text-xs font-semibold uppercase text-[var(--text-muted)]",children:["Filtrar ",p.header]}),t.jsx("button",{type:"button",onClick:et,disabled:!R&&!P,className:"rounded px-1.5 py-0.5 text-xs font-medium text-[var(--primary)] transition-colors hover:bg-[var(--bg-input)] disabled:opacity-40",children:"Limpiar"})]}),p.sortKey&&t.jsxs("div",{className:"grid grid-cols-2 gap-1 border-b border-[var(--border)] p-1",children:[t.jsxs("button",{type:"button",onClick:()=>fr({key:p.key,dir:"asc"}),className:"flex min-w-0 items-center justify-between rounded-md px-2 py-1.5 text-left text-sm transition-colors hover:bg-[var(--bg-input)]",style:{color:"var(--text-main)"},children:[t.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 truncate",children:[t.jsx(q.HiChevronUp,{className:"h-4 w-4 shrink-0 text-[var(--primary)]"}),t.jsx("span",{className:"truncate",children:"Ascendente"})]}),(Xe==null?void 0:Xe.key)===p.key&&Xe.dir==="asc"&&t.jsx(q.HiCheck,{className:"h-4 w-4 shrink-0 text-[var(--primary)]"})]}),t.jsxs("button",{type:"button",onClick:()=>fr({key:p.key,dir:"desc"}),className:"flex min-w-0 items-center justify-between rounded-md px-2 py-1.5 text-left text-sm transition-colors hover:bg-[var(--bg-input)]",style:{color:"var(--text-main)"},children:[t.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 truncate",children:[t.jsx(q.HiChevronDown,{className:"h-4 w-4 shrink-0 text-[var(--primary)]"}),t.jsx("span",{className:"truncate",children:"Descendente"})]}),(Xe==null?void 0:Xe.key)===p.key&&Xe.dir==="desc"&&t.jsx(q.HiCheck,{className:"h-4 w-4 shrink-0 text-[var(--primary)]"})]})]}),t.jsxs("div",{className:"border-b border-[var(--border)] p-2",children:[t.jsxs("div",{className:"grid grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)] gap-2",children:[t.jsx(ar,{value:(P==null?void 0:P.operator)??"",onChange:ve=>{if(!ve){di(p.key);return}ma(p.key,{operator:ve,value:(P==null?void 0:P.value)??"",valueTo:(P==null?void 0:P.valueTo)??""})},options:Cc,placeholder:"Opcion",emptyLabel:"Sin condicion",ariaLabel:"Operador de filtro",searchable:!1,height:34,padding:"0 9px",dropdownMinWidth:260,className:"min-w-0 [&>button]:rounded-md [&>button]:text-sm [&>button]:font-medium"}),(ne==null?void 0:ne.valueMode)!=="none"?t.jsx("input",{value:(P==null?void 0:P.value)??"",onChange:ve=>{P&&ma(p.key,{...P,value:ve.target.value})},disabled:!P,placeholder:"Valor",className:"min-w-0 rounded-md border px-2 py-1.5 text-sm outline-none transition-colors placeholder:text-[var(--text-muted)] focus:border-[var(--primary)] disabled:opacity-50",style:{borderColor:"var(--border)",background:"var(--bg-input)",color:"var(--text-main)"}}):t.jsx("div",{className:"min-h-8 rounded-md border px-2 py-1.5 text-sm text-[var(--text-muted)]",style:{borderColor:"var(--border)",background:"var(--bg-input)"},children:"Automatico"})]}),(ne==null?void 0:ne.valueMode)==="between"&&t.jsx("input",{value:(P==null?void 0:P.valueTo)??"",onChange:ve=>{P&&ma(p.key,{...P,valueTo:ve.target.value})},placeholder:"Valor final",className:"mt-2 w-full rounded-md border px-2 py-1.5 text-xs outline-none transition-colors placeholder:text-[var(--text-muted)] focus:border-[var(--primary)]",style:{borderColor:"var(--border)",background:"var(--bg-input)",color:"var(--text-main)"}})]}),t.jsx("div",{className:"border-b border-[var(--border)] p-2",children:t.jsxs("div",{className:"flex items-center gap-1 rounded-md border px-2 py-1.5 text-sm",style:{borderColor:"var(--border)",background:"var(--bg-input)"},children:[t.jsx(q.HiMagnifyingGlass,{className:"h-4 w-4 shrink-0 text-[var(--text-muted)]"}),t.jsx("input",{value:Jt,onChange:ve=>oa(ve.target.value),placeholder:"Buscar",className:"min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-[var(--text-muted)]",style:{color:"var(--text-main)"}})]})}),t.jsxs("div",{className:"overflow-auto py-1",style:{maxHeight:"max(96px, calc(var(--dt-column-menu-max-height, 520px) - 236px))"},children:[t.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":qe?"mixed":!!Pe,onClick:()=>{p&&(Pe&&!R?ci(p.key,[]):Mo(p.key))},className:"flex w-full min-w-0 items-center gap-2 rounded-md px-2.5 py-1.5 text-left transition-colors hover:bg-[var(--bg-input)]",style:{color:"var(--text-main)"},children:[t.jsxs("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center rounded border",style:{borderColor:Pe||qe?"var(--primary)":"var(--border)",background:Pe||qe?"var(--primary)":"var(--bg-input)",color:"var(--primary-fg)"},children:[qe&&t.jsx(q.HiMinus,{className:"h-3 w-3"}),Pe&&!qe&&t.jsx(q.HiCheck,{className:"h-3 w-3"})]}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:"Seleccionar todo"})]}),Ce.map(ve=>{const Ee=!R||me.includes(ve.value);return t.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":Ee,onClick:()=>Wb(p.key,ve.value,M.map(Ne=>Ne.value),R),className:"flex w-full min-w-0 items-center gap-2 rounded-md px-2.5 py-1.5 text-left transition-colors hover:bg-[var(--bg-input)]",style:{color:"var(--text-main)"},children:[t.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center rounded border",style:{borderColor:Ee?"var(--primary)":"var(--border)",background:Ee?"var(--primary)":"var(--bg-input)",color:"var(--primary-fg)"},children:Ee&&t.jsx(q.HiCheck,{className:"h-3 w-3"})}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:ve.label})]},ve.value)}),Ce.length===0&&t.jsx("div",{className:"px-3 py-3 text-sm text-[var(--text-muted)]",children:"Sin valores"})]})]}):null}),document.body)};o.useEffect(()=>{if(!mn)return;function p(M){So.current&&!So.current.contains(M.target)&&ca.current&&!ca.current.contains(M.target)&&ia(!1)}return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[mn]);function Ci(p,M){if(p.filterValue){const R=p.filterValue(M);return R==null||R===""?"":Cn(R)}return Cn(gr(p.cell(M)))}function Ei(p){return`"${Cn(p).replace(/"/g,'""')}"`}function ka(p){return Cn(p).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function Mi(){return Bt&&Ut>br.length&&Ma.toast.warning(`Exportando ${br.length.toLocaleString("es-MX")} de ${Ut.toLocaleString("es-MX")} (página actual). Usa exportación completa si está disponible.`),br}function sm(){const p=wt.filter(Pe=>!or(Pe)),M=Mi(),R=p.map(Pe=>Ei(gr(Pe.header))).join(","),P=M.map(Pe=>p.map(qe=>Ei(Ci(qe,Pe))).join(",")).join(`
5
+ `),ne=`${R}
6
+ ${P}`,me=new Blob(["\uFEFF"+ne],{type:"text/csv;charset=utf-8;"}),ke=URL.createObjectURL(me),Ce=document.createElement("a");Ce.href=ke,Ce.download=`${It}.csv`,document.body.appendChild(Ce),Ce.click(),document.body.removeChild(Ce),URL.revokeObjectURL(ke)}function lm(){const p=wt.filter(Ce=>!or(Ce)),M=Mi(),R=p.map(Ce=>ka(gr(Ce.header))),ne=M.map(Ce=>p.map(Pe=>ka(Ci(Pe,Ce)))).map(Ce=>`<tr>${Ce.map(Pe=>`<td>${Pe}</td>`).join("")}</tr>`).join(""),me=`<!DOCTYPE html>
7
+ <html lang="es"><head><meta charset="utf-8"><title>${ka(It)}</title>
8
8
  <style>
9
9
  body{font-family:system-ui,sans-serif;font-size:11px;margin:20px;color:#111}
10
10
  h3{margin:0 0 4px;font-size:14px}
@@ -15,20 +15,20 @@ ${ee}`,ne=new Blob(["\uFEFF"+F],{type:"text/csv;charset=utf-8;"}),be=URL.createO
15
15
  tr:nth-child(even) td{background:#f9f9f9}
16
16
  @media print{body{margin:0}@page{margin:1cm}}
17
17
  </style></head><body>
18
- <h3>${xa(Ot)}</h3>
19
- <p>${fr.length} registros · ${new Date().toLocaleDateString("es")}</p>
20
- <table><thead><tr>${E.map(ye=>`<th>${ye}</th>`).join("")}</tr></thead>
21
- <tbody>${F}</tbody></table>
18
+ <h3>${ka(It)}</h3>
19
+ <p>${M.length} registros · ${new Date().toLocaleDateString("es")}</p>
20
+ <table><thead><tr>${R.map(Ce=>`<th>${Ce}</th>`).join("")}</tr></thead>
21
+ <tbody>${ne}</tbody></table>
22
22
  <script>window.onload=()=>{window.print()}<\/script>
23
- </body></html>`,be=window.open("","_blank");be&&(be.document.write(ne),be.document.close())}const wa=()=>!Qe||!dn?null:dt.createPortal(t.jsxs("div",{ref:yo,role:"menu",className:"overflow-hidden rounded-lg border p-1 shadow-xl",style:{...Nb,position:"fixed",zIndex:9999,minWidth:170,borderColor:"var(--border)",background:"var(--bg-card)"},children:[t.jsxs("button",{type:"button",role:"menuitem",className:"flex w-full items-center gap-2.5 rounded-md px-2.5 py-1.5 text-sm transition-colors hover:bg-[var(--bg-input)]",style:{color:"var(--text-main)"},onClick:()=>{Rb(),oa(!1)},children:[t.jsx(q.HiTableCells,{className:"h-4 w-4 shrink-0 text-emerald-500"}),"Descargar CSV / Excel"]}),t.jsxs("button",{type:"button",role:"menuitem",className:"flex w-full items-center gap-2.5 rounded-md px-2.5 py-1.5 text-sm transition-colors hover:bg-[var(--bg-input)]",style:{color:"var(--text-main)"},onClick:()=>{em(),oa(!1)},children:[t.jsx(q.HiDocumentText,{className:"h-4 w-4 shrink-0 text-red-500"}),"Imprimir / PDF"]})]}),document.body),Na=()=>{const p=X&&De.trim().length>0,E=ge!=null&&ge.length?ge:p?[{key:"bql",label:"BQL",value:De}]:[],ee=ie.filter(F=>{const ne=F.trim();return ne?!new Set(Ie.split(`
24
- `).map(ye=>ye.trim()).filter(Boolean)).has(ne):!1}).slice(0,8);return!ae&&wo===0&&!X&&!Qe?null:t.jsxs("div",{className:"relative flex min-h-9 flex-wrap items-center justify-between gap-2 border-b rounded-t-lg px-2 py-1",style:{borderColor:"var(--border)",background:"var(--bg-input)"},children:[t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[wo>0&&t.jsxs("button",{type:"button",onClick:Hb,className:"inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium text-[var(--primary)] transition-colors hover:bg-[var(--bg-card)]",children:[t.jsx(q.HiXMark,{className:"h-3.5 w-3.5"}),wo," filtros"]}),X&&t.jsxs("div",{ref:go,className:"relative flex min-w-0 flex-1 items-center gap-2",children:[t.jsxs("button",{type:"button",onClick:()=>{if(We){ht(!1);return}ba(),ht(!0)},className:"inline-flex h-7 shrink-0 items-center gap-1.5 rounded-md border px-2 text-xs font-bold transition-colors",style:{background:We?"var(--primary)":p?"color-mix(in srgb, var(--primary) 12%, transparent)":"var(--bg-card)",borderColor:We||p?"var(--primary)":"var(--border)",color:We?"var(--primary-fg)":"var(--primary)"},"aria-expanded":We,title:"Abrir filtros BQL",children:[t.jsx(q.HiCommandLine,{className:"h-3.5 w-3.5"}),"BQL",p&&t.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current"}),We?t.jsx(q.HiChevronUp,{className:"h-3.5 w-3.5"}):t.jsx(q.HiChevronDown,{className:"h-3.5 w-3.5"})]}),t.jsx("span",{className:"hidden truncate text-xs text-[var(--text-muted)] sm:inline",children:te}),E.length>0&&t.jsxs("div",{className:"hidden min-w-0 items-center gap-1.5 overflow-hidden lg:flex",children:[E.slice(0,3).map(F=>t.jsxs("span",{className:"inline-flex max-w-44 items-center gap-1 truncate rounded-full px-2 py-1 text-xs font-medium",style:{background:"var(--bg-hover)",border:"1px solid var(--primary)",color:"var(--primary)"},children:[t.jsxs("span",{className:"text-[var(--text-muted)]",children:[F.label,":"]}),t.jsx("span",{className:"truncate",children:F.value})]},F.key)),E.length>3&&t.jsxs("span",{className:"text-xs text-[var(--text-muted)]",children:["+",E.length-3]})]}),p&&t.jsx("button",{type:"button","aria-label":"Limpiar BQL",title:"Limpiar BQL",onClick:li,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-card)] hover:text-[var(--primary)]",children:t.jsx(q.HiXMark,{className:"h-4 w-4"})}),We&&dt.createPortal(t.jsxs("div",{ref:Kl,className:"flex flex-col gap-3 rounded-lg p-3 shadow-2xl",style:{...vb,background:"var(--bg-card)",border:"1px solid color-mix(in srgb, var(--primary) 35%, var(--border))"},children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[ce.map(F=>t.jsxs("button",{type:"button",onMouseDown:ne=>{ne.preventDefault(),ne.stopPropagation()},onClick:ne=>{ne.preventDefault(),ne.stopPropagation(),fa(F.bql)},className:"inline-flex h-7 items-center gap-1.5 rounded-md border px-2.5 text-xs font-semibold transition-colors hover:border-[var(--primary)] hover:text-[var(--primary)]",style:{background:"var(--bg-input)",borderColor:"var(--border)",color:"var(--text-secondary)"},children:[F.icon,F.label]},F.label)),he.length>0&&t.jsxs("button",{type:"button",onClick:()=>gt(F=>!F),className:"inline-flex h-7 items-center gap-1.5 rounded-md px-2 text-xs font-medium text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-input)] hover:text-[var(--primary)]","aria-expanded":zt,children:[t.jsx(q.HiInformationCircle,{className:"h-3.5 w-3.5"}),"Ejemplos"]}),Qt.length>0&&t.jsxs("button",{type:"button",onClick:()=>Wt(F=>!F),className:"inline-flex h-7 items-center gap-1.5 rounded-md px-2 text-xs font-medium text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-input)] hover:text-[var(--primary)]","aria-expanded":lr,children:[t.jsx(q.HiClock,{className:"h-3.5 w-3.5"}),"Historial"]})]}),t.jsxs("div",{className:"overflow-hidden rounded-lg",style:{background:"var(--bg-input)",border:`1.5px solid ${Te?"var(--danger)":p?"var(--primary)":"var(--border)"}`},children:[t.jsx("textarea",{ref:vo,value:Ie,rows:3,onChange:F=>ko(F.target.value,F.target),onKeyDown:F=>{F.key==="Enter"&&!F.shiftKey&&(F.preventDefault(),si(Ie)),F.key==="Escape"&&ht(!1)},placeholder:P,autoComplete:"off",spellCheck:!1,className:"block w-full px-4 py-3 text-sm outline-none",style:{background:"var(--bg-input)",color:"var(--text-main)",border:"none",fontFamily:"'SF Mono', 'Fira Code', 'Consolas', monospace",lineHeight:1.6,maxHeight:180,minHeight:88,overflowY:"auto",resize:"vertical"}}),ee.length>0&&t.jsx("div",{className:"border-t border-[var(--border)] bg-[var(--bg-card)]",children:ee.map(F=>t.jsx("button",{type:"button",onMouseDown:ne=>{ne.preventDefault(),ne.stopPropagation()},onClick:ne=>{ne.preventDefault(),ne.stopPropagation(),fa(F)},className:"block w-full px-4 py-2 text-left text-xs transition-colors hover:bg-[var(--bg-hover)] hover:text-[var(--primary)]",style:{fontFamily:"'SF Mono', 'Fira Code', 'Consolas', monospace"},children:F},F))})]}),t.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[t.jsx("span",{className:"min-w-0 text-xs",style:{color:Te?"var(--danger)":"var(--text-muted)"},children:Te??(p?`${E.length||1} filtro${(E.length||1)===1?"":"s"} activo${(E.length||1)===1?"":"s"}`:"Enter aplica la consulta. Shift + Enter agrega linea.")}),E.map(F=>t.jsxs("span",{className:"inline-flex max-w-56 items-center gap-1 truncate rounded-full px-2 py-1 text-xs font-medium",style:{background:"var(--bg-hover)",border:"1px solid var(--primary)",color:"var(--primary)"},children:[t.jsxs("span",{className:"text-[var(--text-muted)]",children:[F.label,":"]}),t.jsx("span",{className:"truncate",children:F.value})]},F.key))]}),lr&&Qt.length>0&&t.jsxs("div",{className:"overflow-hidden rounded-lg border border-[var(--border)] bg-[var(--bg-input)]",children:[t.jsxs("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-3 py-2",children:[t.jsxs("span",{className:"flex items-center gap-1.5 text-xs font-semibold text-[var(--text-secondary)]",children:[t.jsx(q.HiClock,{className:"h-3.5 w-3.5"}),"Historial"]}),t.jsxs("button",{type:"button",onClick:()=>{Or([]),Wt(!1)},className:"inline-flex items-center gap-1 rounded px-2 py-0.5 text-xs text-[var(--text-muted)]",children:[t.jsx(q.HiTrash,{className:"h-3 w-3"}),"Limpiar"]})]}),Qt.map(F=>t.jsxs("div",{className:"group flex items-center gap-2 border-b border-[var(--border)] px-3 py-2 last:border-b-0",children:[t.jsx("button",{type:"button",onMouseDown:ne=>{ne.preventDefault(),ne.stopPropagation()},onClick:ne=>{ne.preventDefault(),ne.stopPropagation(),fa(F)},className:"min-w-0 flex-1 text-left",children:t.jsx("code",{className:"block truncate text-xs text-[var(--primary)]",children:F})}),t.jsx("button",{type:"button",onClick:()=>Or(ne=>ne.filter(be=>be!==F)),className:"rounded p-1 text-[var(--text-muted)] opacity-0 transition-opacity group-hover:opacity-100",children:t.jsx(q.HiXMark,{className:"h-3.5 w-3.5"})})]},F))]}),zt&&he.length>0&&t.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:he.map(F=>t.jsxs("button",{type:"button",onMouseDown:ne=>{ne.preventDefault(),ne.stopPropagation()},onClick:ne=>{ne.preventDefault(),ne.stopPropagation(),fa(F.bql),gt(!1)},className:"rounded-lg border border-[var(--border)] bg-[var(--bg-input)] p-2 text-left transition-colors hover:border-[var(--primary)]",children:[t.jsx("code",{className:"block truncate text-xs text-[var(--primary)]",children:F.bql}),F.description&&t.jsx("span",{className:"mt-1 block text-xs text-[var(--text-muted)]",children:F.description})]},F.bql))}),t.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-[var(--border)] pt-3",children:[p&&t.jsxs("button",{type:"button",onClick:li,className:"inline-flex h-8 items-center gap-1 rounded-md px-2.5 text-xs font-medium text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-input)] hover:text-[var(--primary)]",children:[t.jsx(q.HiXMark,{className:"h-3.5 w-3.5"}),"Limpiar"]}),t.jsxs("button",{type:"button",onClick:()=>si(Ie),className:"inline-flex h-8 items-center gap-1.5 rounded-md bg-[var(--primary)] px-4 text-xs font-semibold text-[var(--primary-fg)] transition-opacity hover:opacity-90",children:[t.jsx(q.HiCheck,{className:"h-3.5 w-3.5"}),"Aplicar"]})]})]}),document.body)]})]}),Qe&&t.jsx("button",{ref:sa,type:"button","aria-haspopup":"menu","aria-expanded":dn,"aria-label":"Exportar datos",title:"Exportar datos",onClick:()=>{var ne;const F=(ne=sa.current)==null?void 0:ne.getBoundingClientRect();F&&kb({top:F.bottom+4,right:window.innerWidth-F.right}),oa(be=>!be)},className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-card)] hover:text-[var(--primary)] focus:bg-[var(--bg-card)] focus:text-[var(--primary)] ${dn?"bg-[var(--bg-card)] text-[var(--primary)]":""}`,children:t.jsx(q.HiArrowDownTray,{className:"h-4 w-4"})}),ae&&t.jsx("button",{type:"button","aria-haspopup":"menu","aria-expanded":tt&&Ke==="visibility","aria-label":G,title:G,onClick:F=>ci(F,"visibility"),className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-card)] hover:text-[var(--primary)] focus:bg-[var(--bg-card)] focus:text-[var(--primary)] ${tt&&Ke==="visibility"?"bg-[var(--bg-card)] text-[var(--primary)]":""}`,children:t.jsx(q.HiCog6Tooth,{className:"h-4 w-4"})})]})},Ni=()=>{if(!Kb)return null;const p=$c(it,Lo);return t.jsxs("div",{"aria-busy":a,className:`grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-center gap-2 rounded-b-xl border-t text-xs select-none ${B?"px-2 py-0.5":"px-3 py-1"}`,style:{borderColor:"var(--border)",background:"var(--bg-input)"},children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{style:{color:"var(--text-muted)"},children:br===0?"0 filas":`${Gb}–${Zb} de ${br}`}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("span",{style:{color:"var(--text-muted)"},children:"Filas:"}),t.jsx(ar,{value:String(Ft),onChange:E=>Qb(Number(E)),options:Eo.map(E=>({value:String(E),label:String(E)})),placeholder:"Filas",searchable:!1,disabled:a,height:K,padding:Z,className:"shrink-0 [&>button]:rounded-md [&>button]:text-xs [&_svg]:h-3.5 [&_svg]:w-3.5",style:{width:U}})]})]}),t.jsxs("div",{className:"flex items-center justify-center gap-0.5",children:[t.jsx("button",{disabled:a||it<=1,onClick:()=>Do(it-1),onMouseEnter:E=>{E.currentTarget.disabled||(E.currentTarget.style.background="color-mix(in srgb, var(--primary) 14%, var(--bg-card))",E.currentTarget.style.color="var(--primary)")},onMouseLeave:E=>{E.currentTarget.style.background="transparent",E.currentTarget.style.color="var(--text-muted)"},className:"cursor-pointer rounded p-0.5 transition-colors disabled:cursor-not-allowed disabled:opacity-30",style:{background:"transparent",color:"var(--text-muted)"},children:t.jsx(q.HiChevronLeft,{className:"h-3.5 w-3.5"})}),p.map((E,ee)=>E==="..."?t.jsx("span",{className:"px-1",style:{color:"var(--text-muted)"},children:"…"},`e${ee}`):t.jsx("button",{disabled:a,onClick:()=>Do(E),onMouseEnter:F=>{F.currentTarget.disabled||E===it||(F.currentTarget.style.background="color-mix(in srgb, var(--primary) 14%, var(--bg-card))",F.currentTarget.style.color="var(--primary)")},onMouseLeave:F=>{F.currentTarget.style.background=E===it?"var(--primary)":"transparent",F.currentTarget.style.color=E===it?"var(--primary-fg)":"var(--text-muted)"},className:"h-5 w-5 cursor-pointer rounded text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-60",style:{background:E===it?"var(--primary)":"transparent",color:E===it?"var(--primary-fg)":"var(--text-muted)"},children:E},E)),t.jsx("button",{disabled:a||it>=Lo,onClick:()=>Do(it+1),onMouseEnter:E=>{E.currentTarget.disabled||(E.currentTarget.style.background="color-mix(in srgb, var(--primary) 14%, var(--bg-card))",E.currentTarget.style.color="var(--primary)")},onMouseLeave:E=>{E.currentTarget.style.background="transparent",E.currentTarget.style.color="var(--text-muted)"},className:"cursor-pointer rounded p-0.5 transition-colors disabled:cursor-not-allowed disabled:opacity-30",style:{background:"transparent",color:"var(--text-muted)"},children:t.jsx(q.HiChevronRight,{className:"h-3.5 w-3.5"})})]}),t.jsx("div",{"aria-hidden":"true"})]})},tm=()=>t.jsxs("div",{className:"w-full min-w-0 max-w-full flex flex-col rounded-lg overflow-hidden",style:{background:"var(--bg-card)",boxShadow:ha},children:[ya(),wa(),Na(),t.jsx("div",{ref:Jt,className:"min-w-0 max-w-full overflow-hidden",children:t.jsxs("div",{role:"table",className:"text-sm",style:{width:bn,minWidth:ga},children:[t.jsx("div",{role:"rowgroup",style:N?{position:"sticky",top:0,zIndex:10,backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)"}:void 0,children:va()}),t.jsx("div",{role:"rowgroup",children:Array.from({length:Math.min(6,s)}).map((p,E)=>t.jsxs("div",{role:"row",className:"grid",style:{gridTemplateColumns:zr,borderBottom:`1px solid ${He}`},children:[Tt&&t.jsx("div",{role:"cell",className:`${B?"px-2 py-1.5":"px-3 py-2"} w-10`,style:{borderBottom:`1px solid ${He}`,borderRight:`1px solid ${He}`}},"select-cell"),Ct.map((ee,F)=>t.jsx("div",{role:"cell",className:B?"px-2 py-1.5":"px-3 py-2",style:{borderBottom:`1px solid ${He}`,borderRight:`1px solid ${He}`},children:t.jsx("div",{className:"h-3.5 rounded-full animate-pulse",style:{background:"var(--border)",width:`${Jl(E,F)}%`,minWidth:32}})},ee.key))]},E))})]})})]}),Oo="min-w-0 max-w-full overflow-hidden";return re&&lt&&!ze?t.jsx(gn,{rows:s,columns:Math.max(4,Ct.length||7)}):!a&&r.length===0&&!xo?tm():a&&r.length===0?t.jsxs("div",{className:"w-full min-w-0 max-w-full flex flex-col rounded-lg overflow-hidden",style:{background:"var(--bg-card)",boxShadow:ha},children:[ya(),wa(),Na(),t.jsx("div",{ref:Jt,className:Oo,children:t.jsx(Bo.OverlayScrollbarsComponent,{options:{scrollbars:{autoHide:"leave",autoHideDelay:200}},className:"w-full",style:{maxHeight:ei,maxWidth:"100%"},defer:!0,children:t.jsxs("div",{role:"table",className:"text-sm",style:{width:bn,minWidth:ga},children:[t.jsx("div",{role:"rowgroup",style:N?{position:"sticky",top:0,zIndex:10,backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)"}:void 0,children:va()}),t.jsx("div",{role:"rowgroup",children:Array.from({length:s}).map((p,E)=>t.jsxs("div",{role:"row",className:"grid",style:{gridTemplateColumns:zr,borderBottom:`1px solid ${He}`},children:[Tt&&t.jsx("div",{role:"cell",className:`${B?"px-2 py-1.5":"px-3 py-2"} w-10`,style:{borderBottom:`1px solid ${He}`,borderRight:`1px solid ${He}`}},"select-cell"),Ct.map((ee,F)=>{const ne=ma[ee.key],be=ne!==void 0,ye=ee.key===Ao;return t.jsx("div",{role:"cell","data-dt-column-key":ee.key,className:B?"px-2 py-1.5":"px-3 py-2",style:be?{position:"sticky",left:ne,zIndex:1,background:"color-mix(in srgb, var(--bg-card) 72%, transparent)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",boxShadow:ye?`3px 0 6px -2px rgba(0,0,0,0.10), inset 0 -1px 0 ${He}`:`inset 0 -1px 0 ${He}`,borderRight:`1px solid ${He}`}:{borderBottom:`1px solid ${He}`,borderRight:`1px solid ${He}`},children:t.jsx("div",{className:"h-3.5 rounded-full animate-pulse",style:{background:"var(--border)",width:`${Jl(E,F)}%`,minWidth:32}})},ee.key)})]},E))})]})})}),Ni()]}):!a&&r.length===0?t.jsxs("div",{className:"w-full min-w-0 max-w-full flex flex-col rounded-lg overflow-hidden",style:{background:"var(--bg-card)",boxShadow:ha},children:[ya(),wa(),Na(),t.jsx("div",{ref:Jt,className:Oo,children:t.jsx("div",{role:"table",className:"text-sm",style:{width:bn,minWidth:ga},children:t.jsx("div",{role:"rowgroup",style:N?{position:"sticky",top:0,zIndex:10,backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)"}:void 0,children:va()})})}),t.jsxs("div",{className:"flex min-h-[180px] flex-col items-center justify-center gap-3 border-t px-6 py-12 text-center",style:{borderColor:He,background:"linear-gradient(180deg, color-mix(in srgb, var(--bg-input) 58%, transparent), var(--bg-card))"},children:[t.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-full border",style:{borderColor:"color-mix(in srgb, var(--primary) 24%, var(--border))",background:"color-mix(in srgb, var(--primary) 8%, var(--bg-card))",color:"var(--primary)"},children:l??t.jsx(q.HiMagnifyingGlass,{className:"h-5 w-5"})}),t.jsx("p",{className:"max-w-sm text-sm font-medium",style:{color:"var(--text-main)"},children:i}),t.jsx("span",{className:"text-xs",style:{color:"var(--text-muted)"},children:"Ajusta la busqueda o cambia los filtros para ver mas informacion."})]})]}):t.jsxs("div",{className:"w-full min-w-0 max-w-full flex flex-col rounded-lg overflow-hidden",style:{background:"var(--bg-card)",boxShadow:ha},children:[ya(),wa(),Na(),t.jsx("div",{ref:Jt,className:Oo,children:t.jsx(Bo.OverlayScrollbarsComponent,{options:{scrollbars:{autoHide:"leave",autoHideDelay:200}},className:"w-full",style:{maxHeight:ei,maxWidth:"100%"},defer:!0,children:t.jsxs("div",{role:"table",className:"text-sm",style:{width:bn,minWidth:ga},children:[t.jsx("div",{role:"rowgroup",style:N?{position:"sticky",top:0,zIndex:10,backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)"}:void 0,children:va()}),t.jsx("div",{role:"rowgroup",children:mi.map((p,E)=>{const ee=n(p),F=yi(w==null?void 0:w(p)),ne=E>0?yi(w==null?void 0:w(mi[E-1])):null,be=F&&F.key!==(ne==null?void 0:ne.key),ye=Tt&&k.has(ee),Ae=Tt&&(!M||M(p)),Re=_r?(m==null?void 0:m(p))??!0:!1,Xe=Re&&fi.has(ee),vt=!!d||v&&Re,Je=ye&&y?"color-mix(in srgb, var(--primary) 8%, var(--bg-card))":E%2===1?"color-mix(in srgb, var(--bg-input) 30%, var(--bg-card))":"var(--bg-card)";return t.jsxs(o.Fragment,{children:[be&&t.jsx("div",{role:"row",className:`grid ${F.className??""}`,style:{gridTemplateColumns:zr},children:t.jsx("div",{role:"cell",className:B?"px-2 py-2":"px-3 py-3",style:{gridColumn:"1 / -1",background:"color-mix(in srgb, var(--primary) 8%, var(--bg-input))",borderBottom:`1px solid ${He}`,borderRight:`1px solid ${He}`},children:t.jsx("div",{className:"flex min-w-0 items-center justify-between gap-3",children:t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"truncate text-xs font-semibold uppercase tracking-wider text-[var(--text-main)]",children:F.label}),F.description&&t.jsx("div",{className:"mt-0.5 truncate text-xs text-[var(--text-muted)]",children:F.description})]})})})}),t.jsxs("div",{role:"row",onClick:vt?ve=>{const Ee=ve.target;if(!(Ee!=null&&Ee.closest('[data-dt-disable-row-click="true"]'))){if(v&&Re){pi(ee);return}d==null||d(p)}}:void 0,className:`grid transition-colors ${vt?"cursor-pointer":""} ${x?x(p):""}`,style:{gridTemplateColumns:zr,"--dt-row-bg":Je,"--dt-sticky-bg":Je,background:"var(--dt-row-bg)",borderBottom:`1px solid ${He}`},onMouseEnter:ve=>{ye||(ve.currentTarget.style.setProperty("--dt-row-bg","var(--bg-hover)"),ve.currentTarget.style.setProperty("--dt-sticky-bg",Jb))},onMouseLeave:ve=>{ve.currentTarget.style.setProperty("--dt-row-bg",Je),ve.currentTarget.style.setProperty("--dt-sticky-bg",Je)},children:[_r&&t.jsx("div",{role:"cell",className:`${B?"px-2 py-1.5":"px-3 py-2"} flex w-10 items-center justify-center`,style:{borderBottom:`1px solid ${He}`,borderRight:`1px solid ${He}`},"data-dt-disable-row-click":"true",children:Re&&t.jsx("button",{type:"button","aria-label":Xe?"Contraer fila":"Desplegar fila","aria-expanded":Xe,onClick:ve=>{ve.stopPropagation(),pi(ee)},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-input)] hover:text-[var(--primary)]",children:Xe?t.jsx(q.HiChevronDown,{className:"h-4 w-4"}):t.jsx(q.HiChevronRight,{className:"h-4 w-4"})})}),Tt&&t.jsx("div",{role:"cell",className:`${B?"px-2 py-1.5":"px-3 py-2"} flex w-10 items-center justify-center`,style:To?{position:"sticky",left:0,zIndex:3,background:"var(--dt-sticky-bg)",boxShadow:`inset 0 -1px 0 ${He}`}:{borderBottom:`1px solid ${He}`,borderRight:`1px solid ${He}`},onClick:ve=>{ve.stopPropagation(),Ae&&h(ee)},children:t.jsx(vn,{size:"sm",checked:ye,disabled:!Ae,"aria-label":Ae?"Seleccionar fila":"Fila no seleccionable",containerClassName:"items-center",className:Ae?"cursor-pointer":"cursor-not-allowed opacity-50",onClick:ve=>ve.stopPropagation(),onChange:()=>{Ae&&h(ee)}})}),Ct.map(ve=>{const Ee=ma[ve.key],ke=Ee!==void 0,we=ve.key===Ao,Ne=or(ve);return t.jsx("div",{role:"cell","data-dt-column-key":ve.key,"data-dt-disable-row-click":ve.disableRowClick||Ne?"true":void 0,className:`${Ne?"px-2 py-1.5 justify-center text-center":`${B?"px-2 py-1.5":"px-3 py-2"} ${hi(ve.align)}`} flex min-w-0 items-center ${kc} ${ve.className??""}`,style:{overflow:"hidden",whiteSpace:"nowrap",...ke?{position:"sticky",left:Ee,zIndex:3,background:"var(--dt-sticky-bg)",boxShadow:we?`3px 0 6px -2px rgba(0,0,0,0.10), inset 0 -1px 0 ${He}`:`inset 0 -1px 0 ${He}`,borderRight:`1px solid ${He}`}:{borderBottom:`1px solid ${He}`,borderRight:`1px solid ${He}`}},children:t.jsx(rs,{children:t.jsx("div",{"data-dt-autofit-content":!0,className:"inline-block max-w-none align-middle",children:ve.cell(p)})})},ve.key)})]}),Xe&&u&&t.jsx("div",{role:"row",className:"grid",style:{gridTemplateColumns:zr},children:t.jsx("div",{role:"cell",className:B?"px-2 py-2":"px-3 py-3",style:{gridColumn:"1 / -1",background:"color-mix(in srgb, var(--bg-input) 60%, var(--bg-card))",borderBottom:`1px solid ${He}`},children:u(p)})})]},ee)})})]})})}),Ni()]})}const Dc={email:{pattern:/^[^\s@]+@[^\s@]+\.[^\s@]+$/,message:"Correo inválido"},integer:{pattern:/^-?\d+$/,message:"Debe ser un número entero"},date:{pattern:/^\d{4}-\d{2}-\d{2}$/,message:"Fecha inválida"}};function Ic(e,r){if(r.minLength!==void 0&&e.length<r.minLength)return r.message??`Mínimo ${r.minLength} caracteres`;if(r.maxLength!==void 0&&e.length>r.maxLength)return r.message??`Máximo ${r.maxLength} caracteres`;if(!e)return null;if(r.preset){const n=Dc[r.preset];if(!n.pattern.test(e))return r.message??n.message}return r.pattern&&!r.pattern.test(e)?r.message??"Formato inválido":null}const Oc=new Set(["Backspace","Delete","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Tab","Home","End","Enter","Escape"]);function Hc({initialValue:e,type:r,mask:n,onCommit:a,onCancel:s}){const[l,i]=o.useState(e),c=o.useRef(null),d=(n==null?void 0:n.preset)==="date",u=d?"date":r==="number"?"number":"text";return o.useEffect(()=>{var m,b;(m=c.current)==null||m.focus(),d||(b=c.current)==null||b.select()},[d]),t.jsx("input",{ref:c,type:u,value:l,maxLength:n==null?void 0:n.maxLength,onChange:m=>i(m.target.value),onBlur:()=>s(),onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),a(l)),m.key==="Escape"&&(m.preventDefault(),s()),(n==null?void 0:n.preset)==="integer"&&!m.ctrlKey&&!m.metaKey&&!Oc.has(m.key)&&!/^[\d-]$/.test(m.key)&&m.preventDefault()},onClick:m=>m.stopPropagation(),className:"w-full min-w-0 border-0 bg-transparent p-0 text-sm text-[var(--text-main)] outline-none"})}function Bc({initialValue:e,options:r,loading:n,onCommit:a,onCancel:s}){const l=o.useRef(null);return o.useEffect(()=>{if(n)return;const i=setTimeout(()=>{var c,d;(d=(c=l.current)==null?void 0:c.querySelector("button"))==null||d.click()},0);return()=>clearTimeout(i)},[n]),t.jsx("div",{ref:l,className:"w-full",tabIndex:-1,onKeyDown:i=>{i.key==="Escape"&&(i.stopPropagation(),s())},children:t.jsx(ar,{value:e,onChange:i=>{a(i)},options:r,disabled:n,placeholder:n?"Cargando…":"Seleccionar…",triggerVariant:"ghost",height:30,padding:"0 6px",minOptionsForSearch:1,className:"w-full"})})}const Fc={outline:"2px solid var(--primary)",outlineOffset:"-2px",borderRadius:"4px",background:"color-mix(in srgb, var(--primary) 5%, var(--bg-card))"},Oa={outline:"2px solid var(--primary)",outlineOffset:"-2px",borderRadius:"4px"};function Pc({columns:e,data:r,getRowId:n,onCellUpdate:a,readOnly:s=!1,...l}){const[i,c]=o.useState(r),d=o.useRef(null);o.useEffect(()=>{d.current||c(r)},[r]);const[u,m]=o.useState(null);d.current=u;const[b,f]=o.useState(null),g=o.useRef(null);g.current=b;const[v,k]=o.useState({}),[h,C]=o.useState(null),M=o.useRef(null);M.current=h;const[y,x]=o.useState({}),[w,N]=o.useState({}),A=o.useRef(new Set),T=o.useRef(null);o.useEffect(()=>{var W;const j=document.activeElement;(!j||j===document.body)&&((W=T.current)==null||W.focus({preventScroll:!0}))},[]);const U=e.map(j=>{var W,ae,H;return`${j.key}:${((H=(ae=(W=j.editable)==null?void 0:W.select)==null?void 0:ae.options)==null?void 0:H.length)??-1}`}).join("|");o.useEffect(()=>{e.forEach(j=>{var H,D;const W=(D=(H=j.editable)==null?void 0:H.select)==null?void 0:D.options;if(!W)return;const ae=y[j.key];(!A.current.has(j.key)||(ae==null?void 0:ae.length)===0&&W.length>0)&&(A.current.add(j.key),x($=>({...$,[j.key]:W})))})},[U]);const K=o.useCallback(async(j,W)=>{if(A.current.has(j))return;A.current.add(j);const{url:ae,fetchOptions:H}=W.select??{};if(!(!ae&&!H)){N(D=>({...D,[j]:!0}));try{let D=[];if(H)D=await H();else if(ae){const $=await fetch(ae);if(!$.ok)throw new Error("fetch failed");D=await $.json()}x($=>({...$,[j]:D}))}catch{x(D=>({...D,[j]:[]}))}finally{N(D=>({...D,[j]:!1}))}}},[]),Z=o.useRef(i);Z.current=i;const L=o.useRef(a);L.current=a;const Q=o.useRef(n);Q.current=n;const z=o.useRef(e);z.current=e;const se=o.useRef(s);se.current=s,o.useEffect(()=>{if(e.length>0&&r.length>0){const j=e.find(W=>W.selectable!==!1);j&&f({rowId:n(r[0]),colKey:j.key})}},[]),o.useEffect(()=>{if(!b)return;const j=T.current;if(!j)return;const W=j.querySelector(`[data-cell-id="${b.rowId}:${b.colKey}"]`);if(!W)return;const ae=j.querySelector('[role="rowgroup"]');W.style.scrollMarginTop=`${(ae==null?void 0:ae.offsetHeight)??0}px`;const H=j.querySelector('[role="row"]');let D=0;H&&H.querySelectorAll('[role="cell"], [role="columnheader"]').forEach($=>{$.style.position==="sticky"&&$.style.left!==""&&(D=Math.max(D,parseFloat($.style.left)+$.offsetWidth))}),W.style.scrollMarginLeft=`${D}px`,W.scrollIntoView({block:"nearest",inline:"nearest"})},[b]);const re=o.useCallback(j=>{var D;const W=z.current,ae=new Set,H=[];(D=T.current)==null||D.querySelectorAll("[data-cell-id]").forEach($=>{const oe=$.dataset.cellId.split(":")[0];ae.has(oe)||(ae.add(oe),H.push(oe))}),f($=>{if(!$)return $;const oe=W.findIndex(O=>O.key===$.colKey),G=H.indexOf($.rowId);let X=oe,S=G;if(j==="up")S=Math.max(0,G-1);else if(j==="down")S=Math.min(H.length-1,G+1);else if(j==="left"){let O=oe-1;for(;O>=0&&W[O].selectable===!1;)O--;O>=0&&(X=O)}else if(j==="right"){let O=oe+1;for(;O<W.length&&W[O].selectable===!1;)O++;O<W.length&&(X=O)}return X===oe&&S===G?$:{rowId:H[S],colKey:W[X].key}})},[]),R=o.useCallback((j=!0)=>{const W=d.current;m(null),W&&f(W),j&&setTimeout(()=>{var ae;return(ae=T.current)==null?void 0:ae.focus({preventScroll:!0})},0)},[]),V=o.useCallback(async(j,W,ae)=>{var ie;const H=z.current.find(ge=>ge.key===W);if(!(H!=null&&H.editable))return;const{field:D,type:$,mask:oe,validate:G}=H.editable,X=$==="number"?ae===""?null:Number(ae):ae;if(oe){const ge=Ic(ae,oe);if(ge){k(Te=>({...Te,[`${j}:${W}`]:ge}));return}}if(G){const ge=G(X);if(ge){k(Te=>({...Te,[`${j}:${W}`]:ge}));return}}const S=Q.current,O=Z.current.find(ge=>S(ge)===j);if(!O)return;const I=O[D];m(null),k(ge=>{const Te={...ge};return delete Te[`${j}:${W}`],Te});const te=Z.current,P=te.findIndex(ge=>S(ge)===j),ce=te[Math.min(te.length-1,P+1)];if(f({rowId:S(ce),colKey:W}),setTimeout(()=>{var Te,Le;const ge=document.activeElement;(!ge||ge===document.body||(Te=T.current)!=null&&Te.contains(ge))&&((Le=T.current)==null||Le.focus({preventScroll:!0}))},0),String(I??"")===String(X??""))return;const he={...O,[D]:X};c(ge=>ge.map(Te=>S(Te)===j?he:Te)),C({rowId:j,colKey:W});try{await((ie=L.current)==null?void 0:ie.call(L,{row:O,rowId:j,field:D,oldValue:I,newValue:X}))}catch{c(ge=>ge.map(Te=>S(Te)===j?O:Te)),k(ge=>({...ge,[`${j}:${W}`]:"Error al guardar. Intenta de nuevo."}))}finally{C(null)}},[]),B=o.useCallback(j=>{if(M.current){j.preventDefault();return}if(d.current)return;const W=g.current;if(!(!W||!["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Enter","Escape","Tab"].includes(j.key)))switch(j.preventDefault(),j.key){case"ArrowUp":re("up");break;case"ArrowDown":re("down");break;case"ArrowLeft":re("left");break;case"ArrowRight":re("right");break;case"Tab":re(j.shiftKey?"left":"right");break;case"Enter":{const H=z.current.find(D=>D.key===W.colKey);H!=null&&H.editable&&!se.current?(m(W),H.editable.type==="select"&&!A.current.has(W.colKey)&&K(W.colKey,H.editable)):re("down");break}}},[re,K]),le=o.useMemo(()=>e.map(j=>{if(!j.editable||s){const ae={...j};if(delete ae.editable,delete ae.selectable,j.selectable===!1)return{...ae,disableRowClick:!0};const H=ae.cell;return{...ae,className:`relative ${ae.className??""}`.trim(),disableRowClick:!0,cell:D=>{const $=n(D),oe=(b==null?void 0:b.rowId)===$&&(b==null?void 0:b.colKey)===j.key;return t.jsxs(t.Fragment,{children:[t.jsx("span",{"data-cell-id":`${$}:${j.key}`,className:"absolute inset-0 z-10 cursor-default",onClick:()=>{var G;M.current||(f({rowId:$,colKey:j.key}),(G=T.current)==null||G.focus({preventScroll:!0}))}}),oe&&t.jsx("div",{className:"pointer-events-none absolute inset-0 z-20",style:Oa}),t.jsx("span",{className:"relative z-0 pointer-events-none",children:H(D)})]})}}}const W=j.editable;return{...j,className:`relative ${j.className??""}`.trim(),disableRowClick:!0,cell:ae=>{const H=n(ae),D=j.key,$=(u==null?void 0:u.rowId)===H&&(u==null?void 0:u.colKey)===D,oe=(b==null?void 0:b.rowId)===H&&(b==null?void 0:b.colKey)===D,G=v[`${H}:${D}`],X=(h==null?void 0:h.rowId)===H&&(h==null?void 0:h.colKey)===D,S=ae[W.field],O=String(S??""),I=()=>{var P;M.current||(f({rowId:H,colKey:D}),m({rowId:H,colKey:D}),(P=T.current)==null||P.focus({preventScroll:!0}),W.type==="select"&&!A.current.has(D)&&K(D,W))};if($){const P=W.type==="select"?t.jsx(Bc,{initialValue:O,options:y[D]??[],loading:w[D]??!1,onCommit:ce=>V(H,D,ce),onCancel:R}):t.jsx(Hc,{initialValue:O,type:W.type??"text",mask:W.mask,onCommit:ce=>V(H,D,ce),onCancel:R});return t.jsx("div",{className:"absolute inset-0 flex items-center px-2",style:Fc,onClick:ce=>ce.stopPropagation(),children:P})}const te=j.cell(ae);return t.jsxs(t.Fragment,{children:[t.jsx("span",{"data-cell-id":`${H}:${D}`,className:`peer absolute inset-0 z-10 ${X?"cursor-wait":"cursor-pointer"}`,onClick:I}),oe&&!X&&t.jsx("div",{className:"pointer-events-none absolute inset-0 z-20",style:Oa}),X&&t.jsxs("div",{className:"pointer-events-none absolute inset-0 z-20 flex items-center gap-1.5 bg-[var(--bg-card)]/80 px-2",style:Oa,children:[t.jsx("span",{className:"h-3 w-3 shrink-0 animate-spin rounded-full border-2 border-[var(--text-muted)] border-t-transparent","aria-hidden":!0}),t.jsx("span",{className:"truncate text-xs text-[var(--text-muted)]",children:"Guardando…"})]}),t.jsx("span",{className:"relative z-0 inline-flex items-center gap-1 pointer-events-none",children:G?t.jsxs("span",{className:"flex items-center gap-1 text-red-500",children:[t.jsx(q.HiExclamationCircle,{className:"h-3.5 w-3.5 shrink-0"}),t.jsx("span",{className:"truncate text-xs",children:G})]}):t.jsx("span",{className:"truncate",children:te})}),!X&&t.jsx(q.HiPencil,{className:"pointer-events-none absolute right-1 top-1/2 z-0 h-3 w-3 -translate-y-1/2 shrink-0 text-[var(--text-muted)] opacity-0 transition-opacity peer-hover:opacity-40"})]})}}}),[e,s,u,b,h,v,y,w,n,V,R,K]);return t.jsx("div",{ref:T,tabIndex:0,onKeyDown:B,onBlur:j=>{var W;(W=T.current)!=null&&W.contains(j.relatedTarget)||setTimeout(()=>{var H,D;const ae=document.activeElement;ae&&((H=ae.closest)!=null&&H.call(ae,"[data-bonsaif-select-dropdown]"))||(D=T.current)!=null&&D.contains(ae)||R(!1)},0)},style:{width:"100%",minWidth:0,outline:"none"},children:t.jsx(ns,{...l,columns:le,data:i,getRowId:n})})}function st(e){if(e)return new Date(`${e}T12:00:00`)}function $t(e){const r=e.getFullYear(),n=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return`${r}-${n}-${a}`}function yr(e){return e.charAt(0).toUpperCase()+e.slice(1)}function as(e){return e.map(r=>st(r)).filter(r=>!!r)}function _c(e){if(!(e!=null&&e.length))return[];const r=new Set(e.map($t));return Array.from(r).sort()}function Ha(e){return new Intl.DateTimeFormat("es-MX",{weekday:"short"}).format(e)}function os(e){const r=st(e);if(!r)return e;const n=Ha(r).replace(/\.$/u,"").replace(/^\w/u,s=>s.toUpperCase()),a=new Intl.DateTimeFormat("es-MX",{month:"short"}).format(r).replace(/\.$/u,"").toLowerCase();return`${n} - ${r.getDate()} ${a} ${r.getFullYear()}`}const Ba={weekend:{dayOfWeek:[0,6]}},Fa={weekend:"bonsaif-weekend"};function Pa({children:e,className:r="",...n}){const a=String(e??"").toLowerCase().normalize("NFD").replace(new RegExp("\\p{M}","gu"),"").trim(),s=a.startsWith("sab")||a.startsWith("dom")||a==="s"||a==="d";return t.jsx("th",{...n,className:`${r} ${s?"bonsaif-weekday-weekend":""}`.trim(),children:e})}const zc={background:"var(--primary)",color:"var(--primary-fg, #ffffff)",borderRadius:999},Wc={background:"color-mix(in srgb, var(--primary) 22%, transparent)",color:"var(--text-main)",borderRadius:999};function jc({day:e,modifiers:r,...n}){const a=r.range_start||r.range_end||r.selected&&!r.range_middle,s=!!r.range_middle,l=!!r.weekend||e.date.getDay()===0||e.date.getDay()===6;return t.jsx("button",{...n,type:"button",className:`bonsaif-multi-day-btn${a?" is-range-edge":""}${s?" is-range-middle":""}${l?" bonsaif-day-weekend":""} ${n.className??""}`,style:{...a?zc:null,...s?Wc:null,...l?{fontWeight:800}:null,...n.style}})}function qc({startDate:e,endDate:r,onChange:n,minDate:a,viewMonth:s,numberOfMonths:l=1,orientation:i="horizontal",showSummary:c=!0,startLabel:d="Inicio",endLabel:u="Regreso",className:m=""}){const b={from:st(e),to:st(r)},f=st(a),[g,v]=o.useState(()=>st(s||e)??new Date);o.useEffect(()=>{const y=st(s||e);y&&v(y)},[s,e]);const k=o.useMemo(()=>{if(l<=1)return yr(new Intl.DateTimeFormat("es-MX",{month:"long",year:"numeric"}).format(g));const y=new Date(g.getFullYear(),g.getMonth()+l-1,1),x=g.getFullYear()===y.getFullYear(),w=new Intl.DateTimeFormat("es-MX",{month:"short",...x?{}:{year:"numeric"}}).format(g),N=new Intl.DateTimeFormat("es-MX",{month:"short",year:"numeric"}).format(y);return`${yr(w)} – ${yr(N)}`},[g,l]);function h(){v(new Date(g.getFullYear(),g.getMonth()-1,1))}function C(){v(new Date(g.getFullYear(),g.getMonth()+1,1))}const M=l>1?`bonsaif-range-months bonsaif-range-months--multi bonsaif-range-months--${i}`:"bonsaif-range-months";return t.jsxs("div",{className:`bonsaif-calendar bonsaif-date-range-picker ${m}`.trim(),children:[t.jsxs("div",{className:"bonsaif-cal-shell",children:[t.jsxs("div",{className:"bonsaif-cal-toolbar",children:[t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn","aria-label":"Mes anterior",onClick:h,children:t.jsx(q.HiChevronLeft,{size:16})}),t.jsx("span",{className:"bonsaif-cal-title",children:k}),t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn","aria-label":"Mes siguiente",onClick:C,children:t.jsx(q.HiChevronRight,{size:16})})]}),t.jsx(Sa.DayPicker,{mode:"range",selected:b,month:g,onMonthChange:v,onSelect:y=>{const x=y!=null&&y.from?$t(y.from):e,w=y!=null&&y.to?$t(y.to):"";n({startDate:x,endDate:w})},numberOfMonths:l,hideNavigation:!0,weekStartsOn:1,disabled:f?{before:f}:void 0,showOutsideDays:!1,modifiers:Ba,modifiersClassNames:Fa,components:{DayButton:jc,Weekday:Pa},classNames:{root:"bonsaif-range-daypicker w-full",months:M,month:l>1?"bonsaif-multi-month bonsaif-range-month-card":"bonsaif-multi-month",month_caption:l>1?"bonsaif-range-month-caption":"bonsaif-multi-caption-hidden",month_grid:"bonsaif-multi-month-grid",weekdays:"bonsaif-multi-weekdays",weekday:"bonsaif-multi-weekday",week:"bonsaif-multi-week",day:"bonsaif-multi-day",day_button:"bonsaif-multi-day-btn",selected:"bonsaif-range-day-selected",range_start:"bonsaif-range-start",range_middle:"bonsaif-range-middle",range_end:"bonsaif-range-end",today:"bonsaif-multi-day-today",disabled:"bonsaif-multi-day-disabled",hidden:"bonsaif-multi-day-hidden"},formatters:{formatCaption:y=>`${yr(new Intl.DateTimeFormat("es-MX",{month:"long"}).format(y))} ${y.getFullYear()}`,formatWeekdayName:Ha}})]}),c?t.jsx("div",{className:"bonsaif-cal-summary",children:e?t.jsxs("div",{className:"bonsaif-cal-chips",children:[t.jsxs("span",{className:"bonsaif-cal-chip bonsaif-cal-chip--static",children:[d,": ",e]}),r?t.jsxs("span",{className:"bonsaif-cal-chip bonsaif-cal-chip--static",children:[u,": ",r]}):null]}):t.jsx("span",{children:"Sin rango seleccionado"})}):null]})}function ss({day:e,modifiers:r,onDayPointerDown:n,onDayPointerEnter:a,onDayClickSelect:s,...l}){const i=!!(r.disabled||r.hidden),c=!!r.weekend||e.date.getDay()===0||e.date.getDay()===6;return t.jsx("button",{...l,type:"button",disabled:i||l.disabled,className:`${l.className??""}${c?" bonsaif-day-weekend":""}`,style:{...c?{fontWeight:800}:null,...l.style},onPointerDown:d=>{var u;i||(n==null||n(e.date,d),(u=l.onPointerDown)==null||u.call(l,d))},onPointerEnter:()=>{i||a==null||a(e.date)},onClick:d=>{i||(d.preventDefault(),d.stopPropagation(),s==null||s(e.date,d))}})}function ls(e,r){const n=st(e),a=st(r);if(!n||!a)return[];const s=n<=a?n:a,l=n<=a?a:n,i=[],c=new Date(s);for(;c<=l;)i.push($t(c)),c.setDate(c.getDate()+1);return i}function is(e,r=1){const n=e.getDay(),a=r===1?(n+6)%7:n,s=new Date(e);return s.setHours(12,0,0,0),s.setDate(s.getDate()-a),Array.from({length:7},(l,i)=>{const c=new Date(s);return c.setDate(s.getDate()+i),c})}function Qr(e,r,n){const a=new Set(e);for(const s of r)n==="add"?a.add(s):n==="remove"||a.has(s)?a.delete(s):a.add(s);return Array.from(a).sort()}function Uc(e,r){return typeof r!="number"||r<=0||e.length<=r?e:e.slice(-r)}function Cn(e,r,n){return!!(r&&e<r||n&&e>n)}function cs({value:e,onChange:r,disabled:n=!1,minDate:a,maxDate:s,maxDates:l,retainOutsidePrefix:i}){const c=o.useRef(null),d=o.useRef(null),u=o.useRef(!1),m=o.useRef(e);m.current=e;const b=o.useCallback(y=>{let x=y;if(i){const w=m.current.filter(A=>!A.startsWith(i)),N=y.filter(A=>A.startsWith(i));x=[...w,...N].sort()}r==null||r(Uc(x,l))},[l,r,i]),f=o.useCallback(y=>y.filter(x=>!Cn(x,a,s)),[a,s]),g=o.useCallback(()=>{d.current=null},[]);o.useEffect(()=>{const y=()=>g();return window.addEventListener("pointerup",y),window.addEventListener("pointercancel",y),()=>{window.removeEventListener("pointerup",y),window.removeEventListener("pointercancel",y)}},[g]);const v=o.useCallback((y,x,w,N)=>{const A=f(ls(y,x));b(w==="add"?Qr(N,A,"add"):Qr(N,A,"remove"))},[b,f]),k=o.useCallback((y,x)=>{if(n||x.button!==0)return;const w=$t(y);if(Cn(w,a,s)||x.shiftKey)return;u.current=!0;const N=[...m.current],A=N.includes(w)?"remove":"add";d.current={active:!0,mode:A,anchor:w,latest:w,baseline:N},c.current=w,v(w,w,A,N),x.preventDefault()},[v,n,s,a]),h=o.useCallback(y=>{const x=d.current;if(!(x!=null&&x.active)||n)return;const w=$t(y);Cn(w,a,s)||x.latest!==w&&(x.latest=w,v(x.anchor,w,x.mode,x.baseline))},[v,n,s,a]),C=o.useCallback((y,x)=>{if(n)return;const w=$t(y);if(!Cn(w,a,s)){if(u.current&&!x.shiftKey){u.current=!1,x.preventDefault(),x.stopPropagation();return}if(u.current=!1,x.shiftKey&&c.current){x.preventDefault(),x.stopPropagation();const N=f(ls(c.current,w));b(Qr(m.current,N,"add"));return}c.current=w,b(Qr(m.current,[w],"toggle"))}},[b,n,f,s,a]),M=o.useCallback(y=>{if(n)return;const x=f(_c(y));if(!x.length)return;const w=x.every(N=>m.current.includes(N));b(Qr(m.current,x,w?"remove":"add")),c.current=x[0]??c.current},[b,n,f]);return{onDayPointerDown:k,onDayPointerEnter:h,onDayClick:C,toggleWeek:M,endDrag:g}}function Jr(e){return is(e,1)[0]}function ds(e,r){const n=new Date(e);return n.setDate(n.getDate()+r),n}function Vc({value:e=[],onChange:r,minDate:n,maxDate:a,viewMonth:s,maxDates:l,showWeekNumbers:i=!1,viewMode:c,defaultViewMode:d="month",onViewModeChange:u,showSummary:m=!0,className:b="",disabled:f=!1}){const g=o.useMemo(()=>as(e),[e]),v=o.useMemo(()=>new Set(e),[e]),k=st(n),h=st(a),[C,M]=o.useState(()=>st(s||e[0])??new Date),[y,x]=o.useState(()=>Jr(st(s||e[0])??new Date)),[w,N]=o.useState(d),A=c??w;function T(B){c===void 0&&N(B),u==null||u(B)}o.useEffect(()=>{const B=st(s);B&&(M(B),x(Jr(B)))},[s]);const{onDayPointerDown:U,onDayPointerEnter:K,onDayClick:Z,toggleWeek:L}=cs({value:e,onChange:r,disabled:f,minDate:n,maxDate:a,maxDates:l}),Q=o.useCallback(B=>t.jsx(ss,{...B,className:`bonsaif-multi-day-btn ${B.className??""}`,onDayPointerDown:U,onDayPointerEnter:K,onDayClickSelect:Z}),[Z,U,K]),z=o.useMemo(()=>is(y,1),[y]),se=z[6],re=A==="week"?`${new Intl.DateTimeFormat("es-MX",{day:"numeric",month:"short"}).format(z[0])} – ${new Intl.DateTimeFormat("es-MX",{day:"numeric",month:"short",year:"numeric"}).format(se)}`:yr(new Intl.DateTimeFormat("es-MX",{month:"long",year:"numeric"}).format(C));function R(){if(A==="week"){const B=ds(y,-7);x(Jr(B)),M(B);return}M(new Date(C.getFullYear(),C.getMonth()-1,1))}function V(){if(A==="week"){const B=ds(y,7);x(Jr(B)),M(B);return}M(new Date(C.getFullYear(),C.getMonth()+1,1))}return t.jsxs("div",{className:`bonsaif-calendar bonsaif-multi-date-calendar ${b}`,children:[t.jsxs("div",{className:"bonsaif-cal-shell",children:[t.jsxs("div",{className:"bonsaif-cal-view-toggle",role:"tablist","aria-label":"Vista",children:[t.jsx("button",{type:"button",role:"tab","aria-selected":A==="month",className:`bonsaif-cal-view-btn${A==="month"?" is-active":""}`,disabled:f,onClick:()=>{T("month"),M(y)},children:"Mes"}),t.jsx("button",{type:"button",role:"tab","aria-selected":A==="week",className:`bonsaif-cal-view-btn${A==="week"?" is-active":""}`,disabled:f,onClick:()=>{T("week"),x(Jr(C))},children:"Semana"})]}),t.jsxs("div",{className:"bonsaif-cal-toolbar",children:[t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn","aria-label":A==="week"?"Semana anterior":"Mes anterior",disabled:f,onClick:R,children:t.jsx(q.HiChevronLeft,{size:16})}),t.jsx("span",{className:"bonsaif-cal-title",children:re}),t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn","aria-label":A==="week"?"Semana siguiente":"Mes siguiente",disabled:f,onClick:V,children:t.jsx(q.HiChevronRight,{size:16})})]}),t.jsxs("p",{className:"bonsaif-cal-hint",children:["Click · Shift+click rango · Arrastra",i&&A==="month"?" · Semana (nº)":"",A==="week"?" · Botón semana completa":""]}),A==="month"?t.jsx(Sa.DayPicker,{mode:"multiple",required:!1,selected:g,month:C,onMonthChange:M,onSelect:()=>{},hideNavigation:!0,showOutsideDays:!1,weekStartsOn:1,showWeekNumber:i,onWeekNumberClick:(B,le)=>{L(le)},disabled:f?!0:[...k?[{before:k}]:[],...h?[{after:h}]:[]],className:"bonsaif-multi-daypicker",modifiers:Ba,modifiersClassNames:Fa,classNames:{root:"bonsaif-multi-daypicker",months:"bonsaif-multi-months",month:"bonsaif-multi-month",month_caption:"bonsaif-multi-caption-hidden",month_grid:"bonsaif-multi-month-grid",weekdays:i?"bonsaif-multi-weekdays bonsaif-multi-weekdays--with-week":"bonsaif-multi-weekdays",weekday:"bonsaif-multi-weekday",week:i?"bonsaif-multi-week bonsaif-multi-week--with-week":"bonsaif-multi-week",week_number:"bonsaif-week-number",week_number_header:"bonsaif-week-number-header",day:"bonsaif-multi-day",day_button:"bonsaif-multi-day-btn",selected:"bonsaif-multi-day-selected",today:"bonsaif-multi-day-today",disabled:"bonsaif-multi-day-disabled",hidden:"bonsaif-multi-day-hidden"},components:{DayButton:Q,Weekday:Pa},formatters:{formatWeekdayName:Ha}}):t.jsxs("div",{className:"bonsaif-week-view",children:[t.jsx("div",{className:"bonsaif-week-view-head",children:z.map(B=>t.jsx("div",{className:"bonsaif-multi-weekday",children:new Intl.DateTimeFormat("es-MX",{weekday:"short"}).format(B)},`h-${$t(B)}`))}),t.jsx("div",{className:"bonsaif-week-view-days",children:z.map(B=>{const le=$t(B),j=v.has(le),W=f||(n?le<n:!1)||(a?le>a:!1),ae=le===$t(new Date);return t.jsx("div",{className:`bonsaif-multi-day${j?" bonsaif-multi-day-selected":""}${ae?" bonsaif-multi-day-today":""}${W?" bonsaif-multi-day-disabled":""}`,children:t.jsxs("button",{type:"button",className:"bonsaif-multi-day-btn",disabled:W,"aria-pressed":j,onPointerDown:H=>U(B,H),onPointerEnter:()=>K(B),onClick:H=>Z(B,H),children:[t.jsx("span",{className:"bonsaif-week-day-num",children:B.getDate()}),t.jsx("span",{className:"bonsaif-week-day-month",children:new Intl.DateTimeFormat("es-MX",{month:"short"}).format(B)})]})},le)})}),t.jsx("button",{type:"button",className:"bonsaif-week-select-all",disabled:f,onClick:()=>L(z),children:"Marcar / desmarcar semana"})]})]}),m?t.jsx("div",{className:"bonsaif-cal-summary",children:e.length===0?t.jsx("span",{children:"Sin fechas seleccionadas"}):t.jsxs(t.Fragment,{children:[t.jsxs("span",{children:[e.length," ",e.length===1?"fecha":"fechas"]}),t.jsx("div",{className:"bonsaif-cal-chips",children:e.map(B=>t.jsxs("button",{type:"button",className:"bonsaif-cal-chip",disabled:f,onClick:()=>r==null?void 0:r(e.filter(le=>le!==B)),title:`Quitar ${B}`,children:[os(B),t.jsx("span",{"aria-hidden":!0,children:"×"})]},B))})]})}):null]})}const Yc=Array.from({length:12},(e,r)=>r);function Xc({value:e=[],onChange:r,year:n,onYearChange:a,minDate:s,maxDate:l,maxDates:i,showSummary:c=!0,className:d="",disabled:u=!1,readOnly:m=!1}){const b=o.useMemo(()=>as(e),[e]),f=st(s),g=st(l),v=n??(e[0]?Number(e[0].slice(0,4)):new Date().getFullYear()),[k,h]=o.useState(v);o.useEffect(()=>{typeof n=="number"&&h(n)},[n]);function C(T){h(T),a==null||a(T)}const{onDayPointerDown:M,onDayPointerEnter:y,onDayClick:x}=cs({value:e,onChange:r,disabled:u||m,minDate:s,maxDate:l,maxDates:i,retainOutsidePrefix:`${k}-`}),w=o.useCallback(T=>t.jsx(ss,{...T,className:`bonsaif-year-day-btn ${T.className??""}`,onDayPointerDown:M,onDayPointerEnter:y,onDayClickSelect:x}),[x,M,y]),N=b.filter(T=>T.getFullYear()===k),A=u?!0:[...f?[{before:f}]:[],...g?[{after:g}]:[]];return t.jsxs("div",{className:`bonsaif-calendar bonsaif-year-multi-date-calendar${m?" bonsaif-year-multi-date-calendar--readonly":""} ${d}`,children:[t.jsxs("div",{className:"bonsaif-cal-shell bonsaif-year-cal-shell",children:[t.jsxs("div",{className:"bonsaif-cal-toolbar",children:[t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn","aria-label":"Año anterior",disabled:u,onClick:()=>C(k-1),children:t.jsx(q.HiChevronLeft,{size:16})}),t.jsx("span",{className:"bonsaif-cal-title",children:k}),t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn","aria-label":"Año siguiente",disabled:u,onClick:()=>C(k+1),children:t.jsx(q.HiChevronRight,{size:16})})]}),!m&&!u?t.jsx("p",{className:"bonsaif-cal-hint",children:"Click · Shift+click rango · Arrastra para marcar varias"}):null,t.jsx("div",{className:"bonsaif-year-cal-grid",children:Yc.map(T=>{const U=new Date(k,T,1);return t.jsxs("div",{className:"bonsaif-year-cal-month",children:[t.jsx("div",{className:"bonsaif-year-cal-month-title",children:yr(new Intl.DateTimeFormat("es-MX",{month:"long"}).format(U))}),t.jsx(Sa.DayPicker,{mode:"multiple",required:!1,selected:N,month:U,onMonthChange:()=>{},onSelect:()=>{},numberOfMonths:1,hideNavigation:!0,showOutsideDays:!1,weekStartsOn:1,disabled:A,className:"bonsaif-year-month-picker",modifiers:Ba,modifiersClassNames:Fa,classNames:{root:"bonsaif-year-month-picker",months:"bonsaif-year-month-months",month:"bonsaif-year-month-inner",month_caption:"bonsaif-year-month-caption-hidden",month_grid:"bonsaif-year-month-grid",weekdays:"bonsaif-year-weekdays",weekday:"bonsaif-year-weekday",week:"bonsaif-year-week",day:"bonsaif-year-day",day_button:"bonsaif-year-day-btn",selected:"bonsaif-year-day-selected",today:"bonsaif-year-day-today",disabled:"bonsaif-year-day-disabled",hidden:"bonsaif-year-day-hidden"},components:{DayButton:w,Weekday:Pa},formatters:{formatWeekdayName:K=>new Intl.DateTimeFormat("es-MX",{weekday:"narrow"}).format(K)}})]},`${k}-${T}`)})})]}),c?t.jsx("div",{className:"bonsaif-cal-summary",children:e.length===0?t.jsx("span",{children:"Sin fechas seleccionadas"}):t.jsxs(t.Fragment,{children:[t.jsxs("span",{children:[e.length," ",e.length===1?"fecha":"fechas"," ·"," ",k]}),t.jsx("div",{className:"bonsaif-cal-chips",children:e.map(T=>t.jsxs("button",{type:"button",className:"bonsaif-cal-chip",disabled:u||m,onClick:()=>r==null?void 0:r(e.filter(U=>U!==T)),title:`Quitar ${T}`,children:[os(T),t.jsx("span",{"aria-hidden":!0,children:"×"})]},T))})]})}):null]})}const Kc="bonsaif-ui:hide-tooltips";function us(){window.dispatchEvent(new CustomEvent(Kc))}function Gc(e){if(e!==void 0)return typeof e=="number"?`${e}px`:e}function Zc({trigger:e,items:r,align:n="end",width:a=220,disabled:s=!1,className:l="",menuClassName:i="",onOpenChange:c}){const[d,u]=o.useState(!1),[m,b]=o.useState(!1),[f,g]=o.useState({}),v=o.useRef(null),k=o.useRef(null),h=o.useCallback(w=>{u(w),c==null||c(w)},[c]),C=o.useCallback(()=>{const w=v.current;if(!w)return;const N=w.getBoundingClientRect(),A=typeof a=="number"?a:N.width,T=typeof a=="number"?a:Math.max(N.width,180),U=n==="end"?Math.max(8,N.right-T):Math.min(N.left,window.innerWidth-T-8),K=window.innerHeight-N.bottom,Z=K<240&&N.top>K?void 0:N.bottom+6,L=Z===void 0?window.innerHeight-N.top+6:void 0;g({position:"fixed",zIndex:9999,left:U,top:Z,bottom:L,width:Gc(typeof a=="number"?A:a)})},[n,a]);o.useEffect(()=>b(!0),[]),o.useEffect(()=>{if(!d)return;C();const w=A=>{var U,K;const T=A.target;!((U=v.current)!=null&&U.contains(T))&&!((K=k.current)!=null&&K.contains(T))&&h(!1)},N=A=>{A.key==="Escape"&&h(!1)};return document.addEventListener("mousedown",w),window.addEventListener("keydown",N),window.addEventListener("resize",C),window.addEventListener("scroll",C,!0),()=>{document.removeEventListener("mousedown",w),window.removeEventListener("keydown",N),window.removeEventListener("resize",C),window.removeEventListener("scroll",C,!0)}},[d,h,C]);const M=w=>{s||(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),h(!d))},y=o.isValidElement(e)?o.cloneElement(e,{onClick:()=>{s||(us(),h(!d))}}):e,x=d?t.jsx("div",{ref:k,role:"menu","data-bonsaif-overlay":"true",className:`overflow-hidden rounded-lg border border-[var(--border)] bg-[var(--bg-card)] p-1 shadow-xl ${i}`,style:f,children:r.map(w=>t.jsxs("div",{children:[w.separatorBefore&&t.jsx("div",{className:"my-1 border-t border-[var(--border)]"}),t.jsxs("button",{type:"button",role:"menuitem",disabled:w.disabled,onClick:()=>{var N;w.disabled||(us(),(N=w.onSelect)==null||N.call(w),h(!1))},className:"flex w-full min-w-0 items-start gap-2 rounded-md px-2.5 py-1.5 text-left transition-colors hover:bg-[var(--bg-input)] disabled:cursor-not-allowed disabled:opacity-50",style:{color:w.danger?"var(--danger)":"var(--text-main)"},children:[w.icon&&t.jsx("span",{className:"mt-0.5 shrink-0",children:w.icon}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate text-sm font-medium",children:w.label}),w.description&&t.jsx("span",{className:"block truncate text-xs text-[var(--text-muted)]",children:w.description})]})]})]},w.id))}):null;return t.jsxs("span",{ref:v,role:"button",tabIndex:s?-1:0,"aria-haspopup":"menu","aria-expanded":d,onKeyDown:M,className:`inline-flex ${s?"pointer-events-none opacity-60":""} ${l}`,children:[y,m&&x?dt.createPortal(x,document.body):null]})}const Qc=180,fs="bg-[color-mix(in_srgb,var(--bg-main)_72%,transparent)] backdrop-blur-sm";function Jc({open:e,onClose:r,title:n,subtitle:a,leadingIcon:s,confirmLabel:l="Guardar",onConfirm:i,loading:c=!1,confirmDisabled:d=!1,headerActions:u,bodyClassName:m="flex-1 overflow-y-auto px-6 py-5",width:b=440,hasUnsavedChanges:f=!1,unsavedChangesTitle:g="Descartar cambios",unsavedChangesDescription:v="Hay cambios sin guardar. Si cierras el drawer se perderán.",unsavedChangesConfirmLabel:k="Descartar",unsavedChangesCancelLabel:h="Seguir editando",onDiscardChanges:C,disabled:M=!1,disabledMessage:y,children:x}){const[w,N]=o.useState(!1),[A,T]=o.useState(!1),[U,K]=o.useState(!1),Z=o.useCallback(()=>{T(!0),requestAnimationFrame(()=>{requestAnimationFrame(()=>K(!0))})},[]),L=o.useCallback(()=>{K(!1),window.setTimeout(()=>T(!1),Qc)},[]),Q=M||c,z=o.useCallback(()=>{if(!Q){if(f){Z();return}r()}},[Q,f,r,Z]),se=o.useCallback(()=>{K(!1),T(!1),C==null||C(),r()},[r,C]);if(o.useEffect(()=>{N(!0)},[]),o.useEffect(()=>(document.body.style.overflow=e?"hidden":"",e||(K(!1),T(!1)),()=>{document.body.style.overflow=""}),[e]),o.useEffect(()=>{if(!e)return;const R=V=>{if(V.key==="Escape"&&!Q){if(A){L();return}z()}};return window.addEventListener("keydown",R),()=>window.removeEventListener("keydown",R)},[L,Q,A,e,z]),!w)return null;const re=y!==void 0?y:c?"Guardando…":null;return dt.createPortal(t.jsxs("div",{"aria-hidden":!e,"data-bonsaif-overlay":e?"true":void 0,className:`fixed inset-0 z-[1000] flex transition-opacity duration-300 ${e?"opacity-100":"opacity-0 pointer-events-none"}`,children:[t.jsx("div",{className:`absolute inset-0 ${fs}`,onClick:z}),t.jsxs("div",{className:`absolute inset-y-0 right-0 flex flex-col shadow-2xl transition-transform duration-300 ${e?"translate-x-0":"translate-x-full"}`,style:{width:`min(100vw, ${b}px)`,background:"var(--bg-card)",borderLeft:"1px solid var(--border)"},children:[t.jsxs("div",{className:"flex items-center justify-between px-6 py-4 flex-shrink-0",style:{borderBottom:"1px solid var(--border)"},children:[t.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[t.jsx(Ue,{variant:"icon",onClick:z,title:"Cerrar",disabled:Q,children:t.jsx(q.HiXMark,{className:"w-5 h-5"})}),s&&t.jsx("div",{className:"flex-shrink-0",children:s}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("h3",{className:"text-base font-semibold truncate",style:{color:"var(--text-main)"},children:n}),a&&t.jsx("p",{className:"text-xs truncate",style:{color:"var(--text-muted)"},children:a})]})]}),(u||i)&&t.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[u,i&&t.jsxs(t.Fragment,{children:[t.jsx(Ue,{variant:"secondary",size:"sm",onClick:z,disabled:Q,style:{background:"var(--bg-input)"},children:"Cancelar"}),t.jsx(Ue,{variant:"primary",size:"sm",icon:t.jsx(Ci.FiSave,{className:"w-4 h-4"}),onClick:i,loading:c,disabled:d||Q,title:l})]})]})]}),t.jsx("div",{"data-drawer-scroll":"true",className:m,children:x}),Q&&t.jsx("div",{className:"absolute inset-0 z-[1002] flex cursor-not-allowed items-center justify-center p-6",style:{background:"color-mix(in srgb, var(--bg-card, #ffffff) 72%, transparent)",backdropFilter:"blur(3px)"},role:"status","aria-live":"polite","aria-busy":"true",children:re?t.jsxs("div",{className:"flex max-w-xs flex-col items-center gap-3 text-center",children:[t.jsx("div",{className:"h-9 w-9 animate-spin rounded-full border-2 border-[var(--border)] border-t-[var(--primary)]","aria-hidden":!0}),t.jsx("p",{className:"text-sm font-semibold text-[var(--text-main)]",children:re})]}):null})]}),A&&t.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":g,className:"fixed inset-0 z-[1001] flex items-center justify-center p-4",children:[t.jsx("div",{className:`absolute inset-0 ${fs} transition-opacity duration-200 ease-out ${U?"opacity-100":"opacity-0"}`,onClick:L}),t.jsxs("div",{className:`relative z-10 w-full max-w-sm rounded-2xl border p-6 shadow-2xl transition-[opacity,transform] duration-200 ease-out ${U?"translate-y-0 scale-100 opacity-100":"translate-y-2 scale-[0.96] opacity-0"}`,style:{background:"var(--bg-card, #ffffff)",borderColor:"var(--border, #d8e1dc)"},children:[t.jsx(Ue,{variant:"icon",onClick:L,className:"absolute right-3 top-3 h-7 w-7 hover:opacity-70",style:{color:"var(--text-muted, #6b7f78)"},"aria-label":h,children:t.jsx(q.HiXMark,{className:"h-4 w-4"})}),t.jsx("div",{className:"mb-4 flex h-11 w-11 items-center justify-center rounded-xl",style:{background:"var(--warning-bg, #fff7ed)"},children:t.jsx(q.HiExclamationTriangle,{className:"h-5 w-5",style:{color:"var(--warning, #d97706)"}})}),t.jsx("h2",{className:"mb-1 text-base font-semibold",style:{color:"var(--text-main, #0f2f2c)"},children:g}),t.jsx("p",{className:"text-sm",style:{color:"var(--text-muted, #6b7f78)"},children:v}),t.jsxs("div",{className:"mt-6 flex gap-2",children:[t.jsx(Ue,{variant:"secondary",onClick:L,className:"flex-1 border",style:{background:"var(--bg-input, #f7faf8)",borderColor:"var(--border, #d8e1dc)",color:"var(--text-main, #0f2f2c)"},children:h}),t.jsx(Ue,{variant:"secondary",onClick:se,className:"flex-1 border",style:{background:"var(--warning, #d97706)",borderColor:"transparent",color:"#fff",boxShadow:"0 10px 22px rgba(217, 119, 6, 0.22)"},children:k})]})]})]})]}),document.body)}const Rc=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,ed=/^\+?[0-9\s().-]+$/,td=7,rd=15;function At(e){return e==null||String(e).trim()===""}function bs(e){return typeof e=="number"?e:typeof e=="string"&&e.trim()!==""?Number(e):Number.NaN}function _a(e){return At(e)?!1:Rc.test(String(e))}function za(e){if(At(e))return!1;const r=String(e),n=r.replace(/\D/g,"");return ed.test(r)&&n.length>=td&&n.length<=rd}function nd(e="Este campo es requerido."){return r=>At(r)?e:void 0}function ad(e="Ingresa un correo valido."){return r=>At(r)||_a(r)?void 0:e}function od(e="Ingresa un telefono valido."){return r=>At(r)||za(r)?void 0:e}function sd(e,r){return n=>At(n)||String(n).length>=e?void 0:r??`Debe tener al menos ${e} caracteres.`}function ld(e,r){return n=>At(n)||String(n).length<=e?void 0:r??`Debe tener ${e} caracteres o menos.`}function id(e,r){return n=>{if(At(n))return;const a=bs(n);return Number.isFinite(a)&&a>=e?void 0:r??`Debe ser mayor o igual a ${e}.`}}function cd(e,r){return n=>{if(At(n))return;const a=bs(n);return Number.isFinite(a)&&a<=e?void 0:r??`Debe ser menor o igual a ${e}.`}}function dd(e,r="El formato no es valido."){return n=>At(n)||e.test(String(n))?void 0:r}function ud(e,r){const n={};for(const a of Object.keys(r)){const s=r[a];if(!s)continue;const l=Array.isArray(s)?s:[s];for(const i of l){const c=i(e[a],e);if(c){n[a]=c;break}}}return{valid:Object.keys(n).length===0,errors:n}}var ms={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},ps=o.createContext&&o.createContext(ms),fd=["attr","size","title"];function bd(e,r){if(e==null)return{};var n,a,s=md(e,r);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a<l.length;a++)n=l[a],r.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(s[n]=e[n])}return s}function md(e,r){if(e==null)return{};var n={};for(var a in e)if({}.hasOwnProperty.call(e,a)){if(r.indexOf(a)!==-1)continue;n[a]=e[a]}return n}function En(){return En=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var a in n)({}).hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e},En.apply(null,arguments)}function hs(e,r){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);r&&(a=a.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,a)}return n}function Mn(e){for(var r=1;r<arguments.length;r++){var n=arguments[r]!=null?arguments[r]:{};r%2?hs(Object(n),!0).forEach(function(a){pd(e,a,n[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):hs(Object(n)).forEach(function(a){Object.defineProperty(e,a,Object.getOwnPropertyDescriptor(n,a))})}return e}function pd(e,r,n){return(r=hd(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function hd(e){var r=gd(e,"string");return typeof r=="symbol"?r:r+""}function gd(e,r){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var a=n.call(e,r);if(typeof a!="object")return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function gs(e){return e&&e.map((r,n)=>o.createElement(r.tag,Mn({key:n},r.attr),gs(r.child)))}function Wa(e){return r=>o.createElement(vd,En({attr:Mn({},e.attr)},r),gs(e.child))}function vd(e){var r=n=>{var{attr:a,size:s,title:l}=e,i=bd(e,fd),c=s||n.size||"1em",d;return n.className&&(d=n.className),e.className&&(d=(d?d+" ":"")+e.className),o.createElement("svg",En({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,a,i,{className:d,style:Mn(Mn({color:e.color||n.color},n.style),e.style),height:c,width:c,xmlns:"http://www.w3.org/2000/svg"}),l&&o.createElement("title",null,l),e.children)};return ps!==void 0?o.createElement(ps.Consumer,null,n=>r(n)):r(ms)}function vs(e){return Wa({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Zm-8-80V80a8,8,0,0,1,16,0v56a8,8,0,0,1-16,0Zm20,36a12,12,0,1,1-12-12A12,12,0,0,1,140,172Z"},child:[]}]})(e)}function yd(e){return Wa({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M247.31,124.76c-.35-.79-8.82-19.58-27.65-38.41C194.57,61.26,162.88,48,128,48S61.43,61.26,36.34,86.35C17.51,105.18,9,124,8.69,124.76a8,8,0,0,0,0,6.5c.35.79,8.82,19.57,27.65,38.4C61.43,194.74,93.12,208,128,208s66.57-13.26,91.66-38.34c18.83-18.83,27.3-37.61,27.65-38.4A8,8,0,0,0,247.31,124.76ZM128,192c-30.78,0-57.67-11.19-79.93-33.25A133.47,133.47,0,0,1,25,128,133.33,133.33,0,0,1,48.07,97.25C70.33,75.19,97.22,64,128,64s57.67,11.19,79.93,33.25A133.46,133.46,0,0,1,231.05,128C223.84,141.46,192.43,192,128,192Zm0-112a48,48,0,1,0,48,48A48.05,48.05,0,0,0,128,80Zm0,80a32,32,0,1,1,32-32A32,32,0,0,1,128,160Z"},child:[]}]})(e)}function xd(e){return Wa({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M228,175a8,8,0,0,1-10.92-3l-19-33.2A123.23,123.23,0,0,1,162,155.46l5.87,35.22a8,8,0,0,1-6.58,9.21A8.4,8.4,0,0,1,160,200a8,8,0,0,1-7.88-6.69l-5.77-34.58a133.06,133.06,0,0,1-36.68,0l-5.77,34.58A8,8,0,0,1,96,200a8.4,8.4,0,0,1-1.32-.11,8,8,0,0,1-6.58-9.21L94,155.46a123.23,123.23,0,0,1-36.06-16.69L39,172A8,8,0,1,1,25.06,164l20-35a153.47,153.47,0,0,1-19.3-20A8,8,0,1,1,38.22,99c16.6,20.54,45.64,45,89.78,45s73.18-24.49,89.78-45A8,8,0,1,1,230.22,109a153.47,153.47,0,0,1-19.3,20l20,35A8,8,0,0,1,228,175Z"},child:[]}]})(e)}function xr({content:e,ariaLabel:r="Más información",className:n=""}){return t.jsx(nr,{as:"span",content:e,className:`inline-flex shrink-0 align-middle text-[var(--text-muted)] outline-none transition-colors hover:text-[var(--primary)] focus-visible:text-[var(--primary)] ${n}`,children:t.jsx("span",{tabIndex:0,role:"img","aria-label":r,className:"inline-flex items-center justify-center outline-none",children:t.jsx(q.HiInformationCircle,{className:"h-3.5 w-3.5"})})})}function wr({error:e,helperText:r,helperDisplay:n="inline"}){return e?t.jsx("span",{className:"text-xs font-medium normal-case text-[var(--danger)]",children:e}):r&&n!=="tooltip"?t.jsx("span",{className:"text-xs font-medium normal-case text-[var(--text-muted)]",children:r}):null}function Tn({className:e="",...r}){return t.jsx("input",{...r,className:`h-10 rounded-lg border border-[var(--border)] bg-[var(--bg-input)] px-2.5 py-1.5 text-sm text-[var(--text-main)] outline-none placeholder:text-[var(--text-muted)] transition-colors focus:border-[var(--primary)] ${e}`})}function ja({label:e,containerClassName:r="",helperText:n,helperDisplay:a="inline",error:s,errorDisplay:l="inline",errorTooltipLabel:i="Error de validacion",labelAction:c,floatingLabel:d=!1,showPasswordToggle:u=!0,nativeValidation:m=!1,className:b="",required:f,...g}){const[v,k]=o.useState(()=>!!g.autoFocus),[h,C]=o.useState(!1),M=g.type==="password"&&u,y=M&&h?"text":g.type,x=!!s,w=x&&l!=="tooltip",N=x&&l!=="inline",A=!!n&&a==="tooltip"&&!w,T=m?f:void 0,U=x?"border-[var(--danger)] focus:border-[var(--danger)]":"",K=N?M?"pr-20":"pr-10":M?"pr-10":"",Z=g.value!==void 0?String(g.value).length>0:g.defaultValue!==void 0&&String(g.defaultValue).length>0,L=v||Z,Q={top:L?7:12,color:v?"var(--primary)":"var(--text-muted)",fontSize:L?10:13,fontWeight:L?600:400,textTransform:L?"uppercase":"none"},z=B=>{var le;k(!0),(le=g.onFocus)==null||le.call(g,B)},se=B=>{var le;k(!1),(le=g.onBlur)==null||le.call(g,B)},re=M?t.jsxs("button",{type:"button","aria-label":h?"Ocultar contraseña":"Mostrar contraseña","aria-pressed":h,className:"absolute right-2.5 top-1/2 flex h-7 w-7 -translate-y-1/2 items-center justify-center rounded-md text-[var(--text-muted)] transition-colors duration-200 hover:text-[var(--primary)] focus:outline-none",tabIndex:-1,onClick:()=>C(B=>!B),children:[t.jsx("span",{"aria-hidden":"true",className:`absolute inset-0 flex items-center justify-center transition-[opacity,transform] duration-200 ease-out ${h?"scale-y-0 rotate-[-8deg] opacity-0":"scale-y-100 rotate-0 opacity-100"}`,children:t.jsx(yd,{className:"h-[18px] w-[18px]"})}),t.jsx("span",{"aria-hidden":"true",className:`absolute inset-0 flex items-center justify-center transition-[opacity,transform] duration-200 ease-out ${h?"scale-y-100 rotate-0 opacity-100":"scale-y-0 rotate-[8deg] opacity-0"}`,children:t.jsx(xd,{className:"h-[18px] w-[18px]"})})]}):null,R=N?t.jsx(nr,{as:"span",content:s,className:`absolute top-1/2 flex h-7 w-7 -translate-y-1/2 items-center justify-center rounded-md text-[var(--danger)] outline-none transition-colors hover:bg-[var(--danger-bg)] focus-visible:bg-[var(--danger-bg)] ${M?"right-10":"right-2.5"}`,children:t.jsx("span",{tabIndex:0,role:"img","aria-label":i,className:"flex h-full w-full items-center justify-center outline-none",children:t.jsx(vs,{className:"h-[18px] w-[18px]"})})}):null,V=t.jsx(wr,{error:w?s:void 0,helperText:n,helperDisplay:a});return d?t.jsxs("label",{className:`flex flex-col gap-2 ${r}`,children:[t.jsxs("span",{className:"relative block",children:[t.jsx(Tn,{...g,type:y,required:T,placeholder:" ","aria-invalid":x||g["aria-invalid"],"data-has-value":Z?"true":void 0,className:`h-11 w-full pt-5 ${K} ${U} ${b}`,onFocus:z,onBlur:se}),t.jsxs("span",{className:"pointer-events-none absolute left-3 transition-all duration-150",style:Q,children:[e,f&&t.jsx("span",{className:"ml-1 text-[var(--danger)]",children:"*"})]}),c&&t.jsx("span",{className:"absolute right-2 transition-all duration-150",style:{top:L?7:12},children:c}),R,re]}),V]}):t.jsxs("label",{className:`flex flex-col gap-2 ${r}`,children:[t.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-semibold uppercase text-[var(--text-muted)]",children:[t.jsx("span",{children:e}),f&&t.jsx("span",{className:"text-[var(--danger)]",children:"*"}),A?t.jsx(xr,{content:n}):null,c&&t.jsx("span",{className:"ml-auto normal-case",children:c})]}),M?t.jsxs("span",{className:"relative block",children:[t.jsx(Tn,{...g,type:y,required:T,"aria-invalid":x||g["aria-invalid"],className:`w-full ${K} ${U} ${b}`,onFocus:z,onBlur:se}),R,re]}):t.jsxs("span",{className:"relative block",children:[t.jsx(Tn,{...g,required:T,"aria-invalid":x||g["aria-invalid"],className:`w-full ${K} ${U} ${b}`}),R]}),V]})}function ys(e){return e==null?"":String(e)}function wd({autoComplete:e="email",inputMode:r="email",validate:n=!0,invalidMessage:a="Ingresa un correo valido.",errorDisplay:s="tooltip",error:l,value:i,defaultValue:c,onChange:d,...u}){const[m,b]=o.useState(()=>ys(c)),f=i!==void 0?ys(i):m,g=n&&f.length>0&&!_a(f)?a:void 0,v=k=>{i===void 0&&b(k.currentTarget.value),d==null||d(k)};return t.jsx(ja,{...u,value:i,defaultValue:c,type:"text",inputMode:r,autoComplete:e,error:l??g,errorDisplay:s,onChange:v})}const Nd={sm:"min-h-[160px] p-4",md:"min-h-[220px] p-6",lg:"min-h-[300px] p-8"};function kd({title:e="Sin resultados",description:r,icon:n=t.jsx(q.HiInbox,{className:"h-5 w-5"}),action:a,secondaryAction:s,size:l="md",className:i=""}){return t.jsx("div",{className:`flex items-center justify-center rounded-lg border border-[var(--border)] bg-[var(--bg-card)] text-center ${Nd[l]} ${i}`,children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-3",children:[n&&t.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg border border-[var(--border)] bg-[var(--bg-input)] text-[var(--text-muted)]",children:n}),t.jsxs("div",{className:"space-y-1",children:[e&&t.jsx("h3",{className:"text-sm font-semibold text-[var(--text-main)]",children:e}),r&&t.jsx("div",{className:"text-sm leading-5 text-[var(--text-muted)]",children:r})]}),(a||s)&&t.jsxs("div",{className:"mt-1 flex flex-wrap items-center justify-center gap-2",children:[s,a]})]})})}const Sd={sm:"min-h-[112px] p-4",md:"min-h-[148px] p-5",lg:"min-h-[184px] p-6"};function Cd(e){if(e===0)return"0 B";const r=["B","KB","MB","GB"],n=Math.min(Math.floor(Math.log(e)/Math.log(1024)),r.length-1),a=e/1024**n;return`${a>=10||n===0?a.toFixed(0):a.toFixed(1)} ${r[n]}`}function xs(e,r){return r?r.split(",").map(n=>n.trim().toLowerCase()).filter(Boolean).some(n=>{const a=e.name.toLowerCase(),s=e.type.toLowerCase();return n.startsWith(".")?a.endsWith(n):n.endsWith("/*")?s.startsWith(n.slice(0,-1)):s===n}):!0}function Ed(e,r,n){return r?n===void 0?e:e.slice(0,Math.max(0,n)):e.slice(0,1)}function Md({label:e,helperText:r,helperDisplay:n="inline",error:a,labelAction:s,value:l,defaultValue:i=[],onFilesChange:c,onRejectedFiles:d,multiple:u=!1,maxFiles:m,appendFiles:b=!1,showFileList:f=!0,clearable:g=!0,browseLabel:v="Buscar archivos",dropLabel:k="Suelta los archivos aqui",emptyLabel:h="Arrastra y suelta archivos",emptyDescription:C="o haz click para buscarlos en tu equipo",selectedLabel:M="Archivos seleccionados",size:y="md",containerClassName:x="",dropzoneClassName:w="",fileListClassName:N="",className:A="",id:T,accept:U,disabled:K,required:Z,...L}){const Q=o.useId(),z=T??Q,se=o.useRef(null),[re,R]=o.useState(!1),[V,B]=o.useState(i),le=l??V,j=!!a,W=!!r&&n==="tooltip"&&!j,ae=g&&le.length>0&&!K,H=(P,ce)=>{l===void 0&&B(P),c==null||c(P,ce)},D=(P,ce)=>{const he=P.filter(Le=>xs(Le,U)),ie=P.filter(Le=>!xs(Le,U)),ge=b?[...le,...he]:he,Te=Ed(ge,u,m);ie.length>0&&(d==null||d(ie)),H(Te,ce)},$=()=>{var P;K||(P=se.current)==null||P.click()},oe=P=>{D(Array.from(P.target.files??[]),P),P.target.value=""},G=P=>{P.preventDefault(),K||R(!0)},X=P=>{P.currentTarget.contains(P.relatedTarget)||R(!1)},S=P=>{P.preventDefault(),R(!1),!K&&D(Array.from(P.dataTransfer.files),P)},O=P=>{P.key!=="Enter"&&P.key!==" "||(P.preventDefault(),$())},I=P=>{H(le.filter((ce,he)=>he!==P))},te=()=>{H([])};return t.jsxs("div",{className:`flex flex-col gap-2 ${x}`,children:[(e||s||W)&&t.jsxs("div",{className:"inline-flex items-center gap-1 text-xs font-semibold uppercase text-[var(--text-muted)]",children:[e&&t.jsx("span",{children:e}),Z&&t.jsx("span",{className:"text-[var(--danger)]",children:"*"}),W?t.jsx(xr,{content:r}):null,s&&t.jsx("span",{className:"ml-auto normal-case",children:s})]}),t.jsx("input",{...L,ref:se,id:z,type:"file",accept:U,multiple:u,disabled:K,required:Z&&le.length===0,"aria-invalid":j||L["aria-invalid"],className:"sr-only",onChange:oe}),t.jsxs("div",{role:"button",tabIndex:K?-1:0,"aria-controls":z,"aria-disabled":K||void 0,"aria-invalid":j||void 0,className:`flex cursor-pointer flex-col items-center justify-center gap-3 rounded-lg border border-dashed bg-[var(--bg-card)] text-center outline-none transition-colors focus:border-[var(--primary)] focus:bg-[var(--bg-input)] ${Sd[y]} ${re?"border-[var(--primary)] bg-[var(--bg-input)]":j?"border-[var(--danger)]":"border-[var(--border)]"} ${K?"cursor-not-allowed opacity-60":"hover:border-[var(--primary)] hover:bg-[var(--bg-input)]"} ${w} ${A}`,onClick:$,onDragOver:G,onDragLeave:X,onDrop:S,onKeyDown:O,children:[t.jsx("span",{className:"flex h-10 w-10 items-center justify-center rounded-lg border border-[var(--border)] bg-[var(--bg-input)] text-[var(--text-muted)]",children:t.jsx(q.HiArrowUpTray,{className:"h-5 w-5"})}),t.jsxs("span",{className:"space-y-1",children:[t.jsx("span",{className:"block text-sm font-semibold text-[var(--text-main)]",children:re?k:h}),C&&t.jsx("span",{className:"block text-sm text-[var(--text-muted)]",children:C})]}),v&&t.jsx("span",{className:"inline-flex h-9 items-center justify-center rounded-lg border border-[var(--border)] bg-[var(--bg-card)] px-3 text-xs font-semibold text-[var(--text-main)] shadow-sm shadow-black/5 transition-colors",children:v})]}),f&&le.length>0&&t.jsxs("div",{className:`rounded-lg border border-[var(--border)] bg-[var(--bg-card)] ${N}`,children:[t.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--border)] px-3 py-2",children:[t.jsx("span",{className:"text-xs font-semibold uppercase text-[var(--text-muted)]",children:M}),ae&&t.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-input)] hover:text-[var(--danger)] focus:outline-none","aria-label":"Quitar todos los archivos",onClick:te,children:t.jsx(q.HiTrash,{className:"h-4 w-4"})})]}),t.jsx("ul",{className:"divide-y divide-[var(--border)]",children:le.map((P,ce)=>t.jsxs("li",{className:"flex items-center gap-3 px-3 py-2",children:[t.jsx("span",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-[var(--bg-input)] text-[var(--text-muted)]",children:t.jsx(q.HiDocument,{className:"h-4 w-4"})}),t.jsxs("span",{className:"min-w-0 flex-1 text-left",children:[t.jsx("span",{className:"block truncate text-sm font-medium text-[var(--text-main)]",children:P.name}),t.jsx("span",{className:"block text-xs text-[var(--text-muted)]",children:Cd(P.size)})]}),!K&&t.jsx("button",{type:"button",className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-input)] hover:text-[var(--danger)] focus:outline-none","aria-label":`Quitar ${P.name}`,onClick:()=>I(ce),children:t.jsx(q.HiXMark,{className:"h-4 w-4"})})]},`${P.name}-${P.lastModified}-${ce}`))})]}),t.jsx(wr,{error:a,helperText:r,helperDisplay:n})]})}const Td=[{value:"texto",label:"texto"},{value:"numero",label:"número"},{value:"fecha",label:"fecha"},{value:"booleano",label:"booleano"},{value:"email",label:"email"},{value:"telefono",label:"teléfono"},{value:"select",label:"select"},{value:"textarea",label:"textarea"},{value:"archivo",label:"archivo"},{value:"imagen",label:"imagen"}];function $d({fields:e,title:r="Layout",fieldTypes:n=Td,saveLabel:a="Guardar",allowAddField:s=!1,addFieldPlaceholder:l="Nuevo campo",addFieldLabel:i="Anadir",loading:c=!1,onSave:d,onChange:u}){const[m,b]=o.useState(()=>e.map(y=>({key:!1,type:"",...y}))),[f,g]=o.useState(""),[v,k]=o.useState(""),h=o.useCallback((y,x)=>{b(w=>{const N=w.map((A,T)=>T===y?{...A,...x}:A);return u==null||u(N),N})},[u]),C=o.useCallback(()=>{d==null||d(m)},[m,d]),M=o.useCallback(()=>{var N;const y=f.trim();if(!y){k("Ingresa un nombre de campo.");return}if(m.some(A=>A.name.toLowerCase()===y.toLowerCase())){k("Ese campo ya existe en el arreglo.");return}const w={name:y,key:!1,type:((N=n[0])==null?void 0:N.value)??""};b(A=>{const T=[...A,w];return u==null||u(T),T}),g(""),k("")},[n,m,f,u]);return t.jsxs("div",{className:"flex flex-col rounded-xl border shadow-sm",style:{borderColor:"var(--border)",background:"var(--bg-card)",color:"var(--text-main)"},children:[t.jsx("div",{className:"border-b px-6 py-4",style:{borderColor:"var(--border)"},children:t.jsx("span",{className:"text-base font-semibold",style:{color:"var(--text-main)"},children:r})}),t.jsxs("div",{className:"grid grid-cols-[1fr_80px_1fr] gap-4 border-b px-6 py-2 text-xs font-medium uppercase tracking-wide",style:{borderColor:"var(--border)",color:"var(--text-muted)"},children:[t.jsx("span",{children:"Campo"}),t.jsx("span",{className:"text-center",children:"Llave"}),t.jsx("span",{children:"Tipo de Campo"})]}),t.jsxs("div",{className:"max-h-[420px] overflow-y-auto",children:[m.map((y,x)=>t.jsxs("div",{className:"grid grid-cols-[1fr_80px_1fr] items-center gap-4 border-b px-6 py-3 last:border-0 hover:bg-[var(--bg-input)] transition-colors",style:{borderColor:"var(--border)"},children:[t.jsx("span",{className:"text-sm font-medium",style:{color:"var(--text-main)"},children:y.name}),t.jsx("div",{className:"flex justify-center",children:t.jsx(vn,{size:"sm",checked:y.key??!1,onChange:w=>h(x,{key:w.target.checked}),"aria-label":`${y.name} es clave`})}),t.jsx(ar,{value:y.type??"",onChange:w=>h(x,{type:w}),options:n,placeholder:"—",emptyLabel:"—",height:36,searchable:!1,ariaLabel:`Tipo de ${y.name}`})]},y.name)),m.length===0&&t.jsx("p",{className:"px-6 py-8 text-center text-sm",style:{color:"var(--text-muted)"},children:"No hay campos disponibles."})]}),t.jsx("div",{className:"flex justify-end border-t px-6 py-4",style:{borderColor:"var(--border)"},children:t.jsxs("div",{className:"w-full space-y-2",children:[s&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("input",{type:"text",value:f,onChange:y=>{g(y.currentTarget.value),v&&k("")},onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),M())},placeholder:l,className:"min-w-0 flex-1 rounded-lg border px-3 py-2 text-sm outline-none transition-colors",style:{borderColor:"var(--border)",background:"var(--bg-input)",color:"var(--text-main)"},"aria-label":"Nombre del nuevo campo"}),t.jsx(Ue,{variant:"secondary",onClick:M,height:36,padding:"0 12px",children:i})]}),v&&t.jsx("p",{className:"text-xs",style:{color:"var(--danger)"},children:v})]}),t.jsx("div",{className:"flex justify-end",children:t.jsx(Ue,{variant:"primary",onClick:C,disabled:c,loading:c,children:a})})]})})]})}function $n({label:e,children:r,helperText:n,helperDisplay:a="inline",error:s,labelAction:l,required:i=!1,className:c="",contentClassName:d=""}){const u=!!n&&a==="tooltip"&&!s;return t.jsxs("label",{className:`flex flex-col gap-2 ${c}`,children:[(e||l||u)&&t.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-semibold uppercase text-[var(--text-muted)]",children:[e&&t.jsx("span",{children:e}),i&&t.jsx("span",{className:"text-[var(--danger)]",children:"*"}),u?t.jsx(xr,{content:n}):null,l&&t.jsx("span",{className:"ml-auto normal-case",children:l})]}),t.jsx("span",{className:`block ${d}`,children:r}),t.jsx(wr,{error:s,helperText:n,helperDisplay:a})]})}function Ad(e){return Array.from(e.querySelectorAll("img")).filter(r=>!!(r.currentSrc||r.src||"").trim())}function ws(e,r){const n=e.target;if(!(n instanceof HTMLImageElement))return!1;const a=e.currentTarget,s=Ad(a),l=s.indexOf(n);if(l<0)return!1;e.preventDefault(),e.stopPropagation();const i=n.getBoundingClientRect();return r(s.map(c=>({src:c.currentSrc||c.src,alt:c.alt||void 0})),l,{left:i.left,top:i.top,width:i.width,height:i.height}),!0}const Mt=260,Nr=420,qa=380,Lt="cubic-bezier(0.22, 1, 0.36, 1)",Ld="cubic-bezier(0.16, 1, 0.3, 1)",Ua="cubic-bezier(0.22, 1, 0.36, 1)",Dd="cubic-bezier(0.22, 1, 0.36, 1)",Id=8,Od=1,Hd=1.25,Va={background:"color-mix(in srgb, var(--bg-card) 90%, transparent)",border:"1px solid var(--border)",boxShadow:"0 10px 28px color-mix(in srgb, var(--bg-main) 28%, transparent), inset 0 1px 0 color-mix(in srgb, var(--bg-card) 55%, transparent)",color:"var(--text-main)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},Bd="color-mix(in srgb, var(--bg-card) 88%, var(--primary) 12%)",Ya=10;function Rr(e,r,n){return Math.min(n,Math.max(r,e))}function Fd(e){return!e||e.width<1||e.height<1?null:{left:e.left,top:e.top,width:e.width,height:e.height}}function Ns(e,r){if(r.width<1||r.height<1)return{dx:0,dy:0,scale:1};const n=Math.min(e.width/r.width,e.height/r.height),a=e.left+e.width/2-(r.left+r.width/2),s=e.top+e.height/2-(r.top+r.height/2);return{dx:a,dy:s,scale:Number.isFinite(n)?n:1}}function kr({label:e,onClick:r,children:n,disabled:a,size:s="md"}){const l=s==="lg"?44:40;return t.jsx("button",{type:"button","aria-label":e,title:e,disabled:a,onClick:i=>{i.stopPropagation(),r()},className:"inline-flex items-center justify-center rounded-full disabled:cursor-not-allowed disabled:opacity-35",style:{...Va,width:l,height:l,transition:"background 160ms ease, transform 160ms cubic-bezier(0.22, 1, 0.36, 1), opacity 160ms ease"},onMouseEnter:i=>{a||(i.currentTarget.style.background=Bd,i.currentTarget.style.transform="scale(1.06)")},onMouseLeave:i=>{i.currentTarget.style.background=String(Va.background??""),i.currentTarget.style.transform="scale(1)"},onMouseDown:i=>{a||(i.currentTarget.style.transform="scale(0.94)")},onMouseUp:i=>{a||(i.currentTarget.style.transform="scale(1.06)")},children:n})}function ks({open:e,onClose:r,slides:n,index:a,onIndexChange:s,originRect:l=null,maxZoom:i=Id,minZoom:c=Od,zoomStep:d=Hd,closeOnBackdrop:u=!0,closeOnEscape:m=!0,showCounter:b=!0,showZoomControls:f=!0,loop:g=!0,showThumbnails:v=!0,zIndex:k=1100,ariaLabel:h="Visor de imagen"}){const[C,M]=o.useState(!1),[y,x]=o.useState(!1),[w,N]=o.useState(a??0),[A,T]=o.useState(1),[U,K]=o.useState({x:0,y:0}),[Z,L]=o.useState({opacity:1,x:0,scale:1,blur:0,animate:!1}),[Q,z]=o.useState({dx:0,dy:0,scale:1,animate:!1,enabled:!1}),[se,re]=o.useState(!1),R=o.useRef(null),V=o.useRef(null),B=o.useRef(null),le=o.useRef(null),j=o.useRef(null),W=o.useRef(!1),ae=o.useRef(!1),H=o.useRef(null),D=o.useRef(null),$=o.useRef(null),oe=o.useRef(null),G=o.useRef(null),X=o.useRef(a??0),S=a??w,O=n.length===0?0:Rr(S,0,Math.max(0,n.length-1)),I=n[O],te=n.length>1,P=Math.max(c,i),ce=v&&te,he=o.useCallback(de=>{if(n.length===0)return;const pe=n.length-1,Me=g?(de%n.length+n.length)%n.length:Rr(de,0,pe);a===void 0&&N(Me),s==null||s(Me)},[a,g,s,n.length]),ie=o.useCallback(()=>{T(1),K({x:0,y:0})},[]),ge=o.useCallback((de,pe)=>{if(pe<=c+.001)return{x:0,y:0};const Me=oe.current,Pe=G.current;if(!Me||!Pe)return de;const Be=Me.getBoundingClientRect(),Fe=Pe.offsetWidth*pe,tt=Pe.offsetHeight*pe,rt=Math.max(0,(Fe-Be.width)/2+Be.width*.15),Ke=Math.max(0,(tt-Be.height)/2+Be.height*.15);return{x:Rr(de.x,-rt,rt),y:Rr(de.y,-Ke,Ke)}},[c]),Te=o.useCallback(()=>{M(!1),z({dx:0,dy:0,scale:1,animate:!1,enabled:!1}),le.current=null,j.current=null,W.current=!1,ae.current=!1,H.current&&(clearTimeout(H.current),H.current=null)},[]),Le=o.useCallback(()=>{if(W.current)return;W.current=!0,x(!1),ie();const de=le.current,pe=de!=null&&j.current!=null&&j.current===O;if(de&&pe){B.current!=null&&cancelAnimationFrame(B.current),B.current=requestAnimationFrame(()=>{B.current=requestAnimationFrame(()=>{const Me=G.current;if(!Me){B.current=null,R.current&&clearTimeout(R.current),R.current=setTimeout(Te,Mt+40);return}const Pe=Me.getBoundingClientRect(),Be=Ns(de,Pe);z({enabled:!0,dx:0,dy:0,scale:1,animate:!1}),B.current=requestAnimationFrame(()=>{z({enabled:!0,dx:Be.dx,dy:Be.dy,scale:Be.scale,animate:!0}),B.current=null})})}),R.current&&clearTimeout(R.current),R.current=setTimeout(Te,Nr+80);return}z({dx:0,dy:0,scale:1,animate:!1,enabled:!1}),R.current&&clearTimeout(R.current),R.current=setTimeout(Te,Mt+40)},[Te,ie,O]);o.useEffect(()=>(e?(R.current&&clearTimeout(R.current),H.current&&(clearTimeout(H.current),H.current=null),W.current=!1,ae.current=!1,le.current=Fd(l),j.current=le.current!=null?a??w:null,M(!0),x(!1),le.current?z({dx:0,dy:0,scale:1,animate:!1,enabled:!0}):(j.current=null,requestAnimationFrame(()=>requestAnimationFrame(()=>{x(!0),z({dx:0,dy:0,scale:1,animate:!1,enabled:!1})})))):C&&Le(),()=>{R.current&&clearTimeout(R.current),B.current!=null&&cancelAnimationFrame(B.current)}),[e]);const It=o.useCallback(()=>{if(!e||W.current||ae.current)return;const de=le.current,pe=G.current;if(!de||!pe){de||(x(!0),ae.current=!0);return}const Me=pe.getBoundingClientRect();if(Me.width<2||Me.height<2)return;ae.current=!0;const Pe=Ns(de,Me);z({enabled:!0,dx:Pe.dx,dy:Pe.dy,scale:Pe.scale,animate:!1}),B.current!=null&&cancelAnimationFrame(B.current),B.current=requestAnimationFrame(()=>{B.current=requestAnimationFrame(()=>{z({enabled:!0,dx:0,dy:0,scale:1,animate:!0}),x(!0),B.current=null,H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{z({dx:0,dy:0,scale:1,animate:!1,enabled:!1}),H.current=null},Nr+20)})})},[e]);o.useLayoutEffect(()=>{!C||!e||!le.current||ae.current||It()},[C,e,It]),o.useEffect(()=>{!e||W.current||j.current!=null&&j.current!==O&&z(de=>de.enabled?{dx:0,dy:0,scale:1,animate:!1,enabled:!1}:de)},[e,O]),o.useEffect(()=>{if(!e)return;const de=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=de}},[e]),o.useEffect(()=>{e&&ie()},[e,O,ie]),o.useEffect(()=>{a!==void 0&&N(a)},[a]),o.useEffect(()=>{if(!e){X.current=O,L({opacity:1,x:0,scale:1,blur:0,animate:!1});return}const de=X.current;if(de===O)return;X.current=O;const pe=n.length;let Me=1;if(pe>1){const Pe=(de+1)%pe===O,Be=(de-1+pe)%pe===O;Be&&!Pe?Me=-1:Pe&&!Be?Me=1:Me=O>de?1:-1}return V.current!=null&&(cancelAnimationFrame(V.current),V.current=null),L({opacity:0,x:Me*56,scale:.94,blur:8,animate:!1}),V.current=requestAnimationFrame(()=>{V.current=requestAnimationFrame(()=>{L({opacity:1,x:0,scale:1,blur:0,animate:!0}),V.current=null})}),()=>{V.current!=null&&(cancelAnimationFrame(V.current),V.current=null)}},[e,O,n.length]);const ft=A<=c+.001&&Math.abs(U.x)<.5&&Math.abs(U.y)<.5,Qe=o.useCallback((de,pe,Me)=>{T(Pe=>{const Be=Rr(de,c,P);if(Math.abs(Be-Pe)<1e-4)return Pe;const Fe=Be/Pe,tt=Be<Pe;return Be<=c+.001?(K({x:0,y:0}),c):(K(rt=>{let Ke=rt;if(typeof pe=="number"&&typeof Me=="number"&&oe.current&&!tt){const nt=oe.current.getBoundingClientRect(),Oe=pe-nt.left-nt.width/2,Ht=Me-nt.top-nt.height/2;Ke={x:Oe-(Oe-rt.x)*Fe,y:Ht-(Ht-rt.y)*Fe}}else if(tt){Ke={x:rt.x*Fe,y:rt.y*Fe};const nt=Math.min(1,(Pe-Be)/Math.max(.01,Pe-c));Ke={x:Ke.x*(1-nt*.65),y:Ke.y*(1-nt*.65)}}else Ke={x:rt.x*Fe,y:rt.y*Fe};return ge(Ke,Be)}),Be)})},[ge,c,P]),Ot=o.useCallback(()=>{Qe(A*d)},[Qe,A,d]),Se=o.useCallback(()=>{const de=Math.max(c,A/d);if(de<=c+.001){ie();return}T(de),K({x:0,y:0})},[c,ie,A,d]);o.useEffect(()=>{if(!e)return;const de=pe=>{if(pe.key==="Escape"&&m){pe.preventDefault(),r();return}pe.key==="ArrowLeft"&&te?(pe.preventDefault(),he(O-1)):pe.key==="ArrowRight"&&te?(pe.preventDefault(),he(O+1)):pe.key==="+"||pe.key==="="?(pe.preventDefault(),Qe(A*d)):pe.key==="-"||pe.key==="_"?(pe.preventDefault(),Se()):pe.key==="0"&&(pe.preventDefault(),ie())};return window.addEventListener("keydown",de),()=>window.removeEventListener("keydown",de)},[Qe,m,te,r,e,ie,O,A,he,Se,d]);const lt=de=>{de.preventDefault();const pe=de.deltaY>0?1/d:d;Qe(A*pe,de.clientX,de.clientY)},me=de=>{A<=c+.001||(de.currentTarget.setPointerCapture(de.pointerId),re(!0),D.current={pointerId:de.pointerId,startX:de.clientX,startY:de.clientY,originX:U.x,originY:U.y})},Ye=de=>{const pe=D.current;!pe||pe.pointerId!==de.pointerId||K(ge({x:pe.originX+(de.clientX-pe.startX),y:pe.originY+(de.clientY-pe.startY)},A))},qe=de=>{var pe;((pe=D.current)==null?void 0:pe.pointerId)===de.pointerId&&(D.current=null,re(!1))},ct=de=>{if(de.stopPropagation(),A>c+.05){ie();return}Qe(Math.min(P,3),de.clientX,de.clientY)},ze=de=>{if(de.touches.length!==2)return;re(!0);const[pe,Me]=[de.touches[0],de.touches[1]],Pe=Math.hypot(pe.clientX-Me.clientX,pe.clientY-Me.clientY);$.current={distance:Pe,scale:A}},bt=de=>{if(de.touches.length!==2||!$.current)return;de.preventDefault();const[pe,Me]=[de.touches[0],de.touches[1]],Pe=Math.hypot(pe.clientX-Me.clientX,pe.clientY-Me.clientY),Be=(pe.clientX+Me.clientX)/2,Fe=(pe.clientY+Me.clientY)/2,tt=$.current.scale*(Pe/Math.max(1,$.current.distance));Qe(tt,Be,Fe)},mt=()=>{$.current=null,re(!1)};if(!C||!I)return null;const et=Q.enabled,Kt=Q.animate?`transform ${Nr}ms ${Dd}`:"none";return dt.createPortal(t.jsxs("div",{className:"fixed inset-0",style:{zIndex:k},role:"dialog","aria-modal":"true","aria-label":h,children:[t.jsx("button",{type:"button","aria-label":"Cerrar",className:"absolute inset-0 border-0",style:{background:"color-mix(in srgb, var(--bg-sidebar, var(--primary)) 72%, transparent)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",opacity:y?1:0,transition:`opacity ${et?Nr:Mt}ms ${Lt}`,cursor:"default",zIndex:0},onClick:()=>{u&&r()}}),t.jsx("div",{ref:oe,className:"absolute inset-0 flex items-center justify-center",style:{zIndex:1,padding:ce?"4.5rem 3.5rem 6.5rem":"4.5rem 3.5rem 2.5rem",opacity:et||y?1:0,transform:et||y?"translateY(0) scale(1)":"translateY(10px) scale(0.96)",transition:et?"none":`opacity ${Mt}ms ${Lt}, transform ${Mt}ms ${Lt}`},onClick:de=>{de.target===de.currentTarget&&u&&r()},onWheel:lt,children:t.jsx("div",{className:"relative flex max-h-full max-w-full items-center justify-center will-change-transform",style:{transform:Q.enabled?`translate3d(${Q.dx}px, ${Q.dy}px, 0) scale(${Q.scale})`:void 0,transformOrigin:"center center",transition:Q.enabled?Kt:void 0},children:t.jsx("div",{className:"relative flex max-h-full max-w-full items-center justify-center will-change-transform",style:{opacity:Z.opacity,filter:Z.blur?`blur(${Z.blur}px)`:"blur(0px)",transform:`translate3d(${Z.x}px, 0, 0) scale(${Z.scale})`,transition:Z.animate?[`opacity ${qa}ms ${Ua}`,`transform ${qa}ms ${Ua}`,`filter ${qa}ms ${Ua}`].join(", "):"none"},children:t.jsx("div",{ref:G,className:"pointer-events-auto relative max-h-full max-w-full touch-none select-none will-change-transform",style:{cursor:A>c+.001?"grab":"zoom-in",transform:`translate3d(${U.x}px, ${U.y}px, 0) scale(${A})`,transformOrigin:"center center",transition:se?"none":`transform 220ms ${Ld}`},onClick:de=>de.stopPropagation(),onDoubleClick:ct,onPointerDown:me,onPointerMove:Ye,onPointerUp:qe,onPointerCancel:qe,onTouchStart:ze,onTouchMove:bt,onTouchEnd:mt,children:t.jsx("img",{src:I.src,alt:I.alt||"",draggable:!1,className:"block max-h-[min(78vh,820px)] max-w-[min(86vw,1100px)] object-contain",style:{display:"block",borderRadius:Ya,imageRendering:A>2.5?"pixelated":"auto"},onLoad:()=>{It()}},I.src+String(O))})})})}),t.jsxs("div",{className:"pointer-events-none absolute inset-0",style:{zIndex:2,opacity:y?1:0,transform:y?"translateY(0)":"translateY(-6px)",transition:`opacity ${et?Nr:Mt}ms ${Lt}, transform ${et?Nr:Mt}ms ${Lt}`},children:[t.jsxs("div",{className:"pointer-events-none absolute inset-x-0 top-0 flex items-center justify-between gap-3 px-4 pt-4",children:[t.jsx("div",{className:"pointer-events-auto flex items-center gap-2",children:b&&n.length>0?t.jsxs("span",{className:"rounded-full px-3 py-1.5 text-xs font-semibold tracking-wide",style:Va,children:[O+1," / ",n.length]}):null}),t.jsxs("div",{className:"pointer-events-auto flex items-center gap-2",children:[f?t.jsxs(t.Fragment,{children:[t.jsx(kr,{label:"Alejar",onClick:Se,disabled:A<=c+.001,children:t.jsx(q.HiMinus,{className:"h-5 w-5"})}),t.jsx(kr,{label:"Restablecer tamaño",onClick:ie,disabled:ft,children:t.jsx(q.HiArrowsPointingIn,{className:"h-5 w-5"})}),t.jsx(kr,{label:"Acercar",onClick:Ot,disabled:A>=P-.001,children:t.jsx(q.HiPlus,{className:"h-5 w-5"})})]}):null,t.jsx(kr,{label:"Cerrar",onClick:r,children:t.jsx(q.HiXMark,{className:"h-5 w-5"})})]})]}),te?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"pointer-events-auto absolute left-3 top-1/2",style:{opacity:y?1:0,transform:y?"translate(0, -50%)":"translate(-8px, -50%)",transition:`opacity ${Mt}ms ${Lt}, transform ${Mt}ms ${Lt}`},children:t.jsx(kr,{label:"Anterior",size:"lg",onClick:()=>he(O-1),disabled:!g&&O<=0,children:t.jsx(q.HiChevronLeft,{className:"h-6 w-6"})})}),t.jsx("div",{className:"pointer-events-auto absolute right-3 top-1/2",style:{opacity:y?1:0,transform:y?"translate(0, -50%)":"translate(8px, -50%)",transition:`opacity ${Mt}ms ${Lt}, transform ${Mt}ms ${Lt}`},children:t.jsx(kr,{label:"Siguiente",size:"lg",onClick:()=>he(O+1),disabled:!g&&O>=n.length-1,children:t.jsx(q.HiChevronRight,{className:"h-6 w-6"})})})]}):null,ce?t.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 flex justify-center px-4 pb-4 pt-8",style:{background:"linear-gradient(to top, color-mix(in srgb, var(--bg-sidebar, var(--primary)) 72%, transparent), transparent)"},children:t.jsx("div",{className:"pointer-events-auto flex max-w-full items-end gap-2.5 overflow-x-auto rounded-2xl px-2 py-2",style:{background:"color-mix(in srgb, var(--bg-card) 55%, transparent)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",scrollbarWidth:"thin"},role:"tablist","aria-label":"Miniaturas",children:n.map((de,pe)=>{const Me=pe===O;return t.jsx("button",{type:"button",role:"tab","aria-selected":Me,"aria-label":de.alt||`Imagen ${pe+1}`,onClick:Pe=>{Pe.stopPropagation(),he(pe)},className:"relative shrink-0 overflow-hidden transition-opacity",style:{width:56,height:42,borderRadius:Ya,opacity:Me?1:.42,transition:`opacity 180ms ${Lt}`},children:t.jsx("img",{src:de.src,alt:"",draggable:!1,className:"h-full w-full object-cover",style:{borderRadius:Ya}})},`${de.src}-${pe}`)})})}):null]})]}),document.body)}function Pd({children:e,className:r,style:n,maxZoom:a,minZoom:s,zoomStep:l,loop:i,showThumbnails:c}){const[d,u]=o.useState(!1),[m,b]=o.useState(0),[f,g]=o.useState([]),[v,k]=o.useState(null),h=o.useCallback((M,y,x)=>{g(M),k(x??null),b(y),u(!0)},[]),C=o.useCallback(M=>{ws(M,h)},[h]);return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:`[&_img]:cursor-zoom-in ${r??""}`,style:n,onClick:C,children:e}),t.jsx(ks,{open:d,onClose:()=>u(!1),index:m,onIndexChange:b,slides:f,originRect:v,maxZoom:a,minZoom:s,zoomStep:l,loop:i,showThumbnails:c})]})}function Ss(e){if(e!==void 0)return typeof e=="number"?`${e}px`:e}function Cs(e,r){if(e.length!==r.length)return!1;const n=new Set(r);return e.every(a=>n.has(a))}function Xa(e){return e.normalize("NFD").replace(new RegExp("\\p{M}","gu"),"").toLowerCase()}function _d(e,r){if(!r)return!0;const n=Xa(r);return Xa(e.label).includes(n)||!!(e.sublabel&&Xa(e.sublabel).includes(n))}function zd({value:e,onChange:r,options:n,placeholder:a="Seleccionar…",disabled:s=!1,className:l="",style:i,height:c=40,padding:d="6px 10px",searchable:u=!0,minOptionsForSearch:m=6,maxVisibleValues:b=2,truncateSelectedValues:f=!0,emptyText:g="Sin resultados",clearLabel:v="Limpiar seleccion",pruneMissingValues:k=!0}){const[h,C]=o.useState(!1),[M,y]=o.useState(""),[x,w]=o.useState(0),[N,A]=o.useState(!1),[T,U]=o.useState({}),K=o.useRef(null),Z=o.useRef(null),L=o.useRef(null),Q=o.useRef(null),z=u&&n.length>=m,se=o.useMemo(()=>new Set(e),[e]),re=o.useMemo(()=>{const S=new Map;for(const O of n)S.set(O.value,O);return S},[n]),R=o.useMemo(()=>{const S=[];for(const O of e){const I=re.get(O);I&&S.push(I)}return S},[re,e]),V=b==="all"?R.length:b,B=R.slice(0,V),le=Math.max(0,R.length-B.length),j=o.useMemo(()=>{const S=M.trim();return!z||!S?n:n.filter(O=>_d(O,S))},[n,M,z]),W=o.useCallback(()=>{const S=K.current;if(!S)return;const O=S.getBoundingClientRect(),I=z?304:244,te=window.innerHeight-O.bottom,P=te<I&&O.top>te;U({position:"fixed",left:O.left,top:P?void 0:O.bottom+4,bottom:P?window.innerHeight-O.top+4:void 0,width:Math.max(O.width,240),zIndex:9999})},[z]),ae=o.useCallback(S=>{Cs(e,S)||r(S)},[r,e]),H=o.useCallback(S=>{const O=re.get(S);if(O!=null&&O.disabled)return;const I=se.has(S)?e.filter(te=>te!==S):[...e,S];ae(I)},[ae,re,e,se]),D=o.useCallback(()=>ae([]),[ae]),$=o.useCallback(()=>{C(!1),y(""),w(0)},[]);o.useEffect(()=>A(!0),[]);const oe=o.useMemo(()=>n.map(S=>S.value).join("\0"),[n]);o.useEffect(()=>{if(!k||e.length===0||n.length===0)return;const S=new Set(n.map(I=>I.value)),O=e.filter(I=>S.has(I));Cs(e,O)||r(O)},[oe]),o.useEffect(()=>{if(!h)return;function S(O){var te,P;const I=O.target;!((te=K.current)!=null&&te.contains(I))&&!((P=Z.current)!=null&&P.contains(I))&&$()}return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[$,h]),o.useEffect(()=>{h&&(w(0),W(),z&&setTimeout(()=>{var S;return(S=L.current)==null?void 0:S.focus()},0))},[h,z,W]),o.useEffect(()=>{if(h)return window.addEventListener("resize",W),window.addEventListener("scroll",W,!0),()=>{window.removeEventListener("resize",W),window.removeEventListener("scroll",W,!0)}},[h,W]),o.useEffect(()=>{if(j.length===0){w(0);return}w(S=>Math.min(S,j.length-1))},[j.length]),o.useEffect(()=>{if(x<0||!Q.current)return;const S=Q.current.children[x];S==null||S.scrollIntoView({block:"nearest"})},[x]);function G(S){if(!s){if(!h){(S.key==="Enter"||S.key===" "||S.key==="ArrowDown")&&(S.preventDefault(),C(!0));return}if(S.key==="Escape"){S.preventDefault(),$();return}if(S.key==="ArrowDown"){if(S.preventDefault(),j.length===0)return;w(O=>Math.min(O+1,j.length-1));return}if(S.key==="ArrowUp"){S.preventDefault(),w(O=>Math.max(O-1,0));return}if(S.key==="Enter"&&j[x]&&!j[x].disabled){S.preventDefault(),H(j[x].value);return}S.key==="Backspace"&&!M&&e.length&&(S.preventDefault(),ae(e.slice(0,-1)))}}const X=t.jsxs("div",{ref:Z,className:"overflow-hidden rounded-xl shadow-xl",style:{...T,background:"var(--bg-card)",border:"1px solid var(--border)"},children:[z&&t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",style:{borderBottom:"1px solid var(--border)"},children:[t.jsx(q.HiMagnifyingGlass,{className:"h-3.5 w-3.5 flex-shrink-0",style:{color:"var(--text-muted)"}}),t.jsx("input",{ref:L,value:M,onChange:S=>{y(S.target.value),w(0)},onKeyDown:S=>{(S.key==="ArrowDown"||S.key==="ArrowUp"||S.key==="Enter"||S.key==="Escape")&&(S.stopPropagation(),G(S))},placeholder:"Buscar…",className:"min-w-0 flex-1 bg-transparent text-sm outline-none",style:{color:"var(--text-main)"}}),M&&t.jsx("button",{type:"button","aria-label":"Limpiar búsqueda",onMouseDown:S=>{S.preventDefault(),y(""),w(0)},children:t.jsx(q.HiXMark,{className:"h-3.5 w-3.5",style:{color:"var(--text-muted)"}})})]}),e.length>0&&t.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-2 text-xs",style:{borderBottom:"1px solid var(--border)",color:"var(--text-muted)"},children:[t.jsxs("span",{children:[R.length," seleccionados",e.length>R.length?` (${e.length-R.length} no disponibles)`:""]}),t.jsx("button",{type:"button",onMouseDown:S=>{S.preventDefault(),D()},className:"font-semibold transition-colors hover:text-[var(--primary)]",children:v})]}),t.jsxs("ul",{ref:Q,role:"listbox","aria-multiselectable":"true",className:"overflow-y-auto",style:{maxHeight:z?220:200,scrollbarWidth:"thin",scrollbarColor:"var(--border) transparent",overscrollBehavior:"contain"},children:[j.map((S,O)=>{const I=O===x,te=se.has(S.value);return t.jsxs("li",{role:"option","aria-selected":te,onMouseDown:P=>{P.preventDefault(),!S.disabled&&H(S.value)},onMouseEnter:()=>!S.disabled&&w(O),className:"flex cursor-pointer items-center gap-2 px-3 py-2 text-sm transition-colors",style:{background:I?"var(--bg-hover)":te?"color-mix(in srgb, var(--primary) 6%, transparent)":"transparent",color:S.disabled?"var(--text-muted)":"var(--text-main)",cursor:S.disabled?"not-allowed":"pointer",opacity:S.disabled?.58:1},children:[t.jsx("span",{className:"flex h-4 w-4 flex-shrink-0 items-center justify-center rounded border",style:{borderColor:te?"var(--primary)":"var(--border)",background:te?"var(--primary)":"var(--bg-input)",color:"var(--primary-fg)"},children:te&&t.jsx(q.HiCheck,{className:"h-3 w-3"})}),S.color&&t.jsx("span",{className:"h-2.5 w-2.5 flex-shrink-0 rounded-full",style:{background:S.color}}),t.jsxs("span",{className:"flex min-w-0 flex-1 items-baseline gap-1 overflow-hidden",children:[t.jsx("span",{className:"truncate",children:S.label}),S.sublabel&&t.jsx("span",{className:"min-w-0 flex-shrink truncate",style:{color:"var(--text-muted)",fontSize:12},children:S.sublabel})]}),S.badge&&t.jsx("span",{className:"flex-shrink-0 text-xs",style:{color:"var(--text-muted)"},children:S.badge})]},S.value)}),j.length===0&&t.jsx("li",{className:"px-3 py-4 text-center text-sm",style:{color:"var(--text-muted)"},children:g})]})]});return t.jsxs("div",{ref:K,className:`relative ${l||"w-full"}`,style:i,onKeyDown:G,children:[t.jsxs("button",{type:"button",disabled:s,onClick:()=>{s||(h?$():C(!0))},className:"flex w-full items-center gap-2 rounded-lg text-left text-sm transition-colors focus:outline-none",style:{minHeight:Ss(c),padding:Ss(d),background:"var(--bg-input)",color:R.length?"var(--text-main)":"var(--text-muted)",border:h?"1px solid var(--primary)":"1px solid var(--border)",opacity:s?.5:1,cursor:s?"not-allowed":"pointer"},"aria-haspopup":"listbox","aria-expanded":h,children:[t.jsx("span",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1.5 overflow-hidden",children:B.length?t.jsxs(t.Fragment,{children:[B.map(S=>t.jsxs("span",{className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 text-xs font-semibold ${f?"max-w-[160px]":"max-w-full whitespace-normal"}`,style:{background:"var(--bg-card)",borderColor:"var(--border)",color:"var(--text-main)"},children:[S.color&&t.jsx("span",{className:"h-1.5 w-1.5 flex-shrink-0 rounded-full",style:{background:S.color}}),t.jsx("span",{className:f?"truncate":"break-words",children:S.label}),t.jsx("span",{role:"button",tabIndex:-1,"aria-label":`Quitar ${S.label}`,onMouseDown:O=>{O.preventDefault(),O.stopPropagation(),H(S.value)},className:"flex-shrink-0 rounded-full p-0.5 transition-colors hover:bg-black/10",style:{color:"var(--text-muted)"},children:t.jsx(q.HiXMark,{className:"h-3 w-3"})})]},S.value)),le>0&&t.jsxs("span",{className:"inline-flex items-center rounded-md px-1.5 py-0.5 text-xs font-semibold",style:{background:"color-mix(in srgb, var(--primary) 10%, transparent)",color:"var(--primary)"},children:["+",le]})]}):t.jsx("span",{className:"truncate",children:a})}),R.length?t.jsx("span",{role:"button",tabIndex:-1,"aria-label":v,onMouseDown:S=>{S.preventDefault(),S.stopPropagation(),D()},className:"flex-shrink-0 rounded-full p-0.5 transition-colors hover:bg-black/10",style:{color:"var(--text-muted)"},children:t.jsx(q.HiXMark,{className:"h-3.5 w-3.5"})}):t.jsx(q.HiChevronDown,{className:"h-4 w-4 flex-shrink-0 transition-transform",style:{color:"var(--text-muted)",transform:h?"rotate(180deg)":"rotate(0deg)"}})]}),h&&N&&dt.createPortal(X,document.body)]})}function Wd({inputMode:e="decimal",...r}){return t.jsx(ja,{...r,type:"number",inputMode:e})}function jd(e,r,n){const a=[],s=Math.max(2,e-n),l=Math.min(r-1,e+n);a.push(1),s>2&&a.push("...");for(let i=s;i<=l;i+=1)a.push(i);return l<r-1&&a.push("..."),r>1&&a.push(r),a}function qd({page:e,totalPages:r,onPageChange:n,disabled:a=!1,siblingCount:s=1,className:l=""}){const i=Math.max(1,r),c=Math.min(Math.max(1,e),i),d=jd(c,i,s);return t.jsxs("nav",{"aria-label":"Paginacion",className:`inline-flex items-center gap-1 ${l}`,children:[t.jsx(Ue,{variant:"icon",size:"xs","aria-label":"Pagina anterior",disabled:a||c<=1,onClick:()=>n(c-1),children:t.jsx(q.HiChevronLeft,{className:"h-4 w-4"})}),d.map((u,m)=>u==="..."?t.jsx("span",{className:"flex h-8 min-w-8 items-center justify-center text-xs font-semibold text-[var(--text-muted)]",children:"..."},`ellipsis-${m}`):t.jsx("button",{type:"button","aria-current":u===c?"page":void 0,disabled:a,onClick:()=>n(u),className:"flex h-8 min-w-8 items-center justify-center rounded-md border px-2 text-xs font-semibold transition-colors disabled:cursor-not-allowed disabled:opacity-50",style:{borderColor:u===c?"var(--primary)":"var(--border)",background:u===c?"var(--primary)":"var(--bg-card)",color:u===c?"var(--primary-fg)":"var(--text-secondary)"},children:u},u)),t.jsx(Ue,{variant:"icon",size:"xs","aria-label":"Pagina siguiente",disabled:a||c>=i,onClick:()=>n(c+1),children:t.jsx(q.HiChevronRight,{className:"h-4 w-4"})})]})}const Es=[{value:"+1",label:"+1",sublabel:"Estados Unidos, Canada, Caribe"},{value:"+7",label:"+7",sublabel:"Rusia, Kazajistan"},{value:"+20",label:"+20",sublabel:"Egipto"},{value:"+27",label:"+27",sublabel:"Sudafrica"},{value:"+30",label:"+30",sublabel:"Grecia"},{value:"+31",label:"+31",sublabel:"Paises Bajos"},{value:"+32",label:"+32",sublabel:"Belgica"},{value:"+33",label:"+33",sublabel:"Francia"},{value:"+34",label:"+34",sublabel:"Espana"},{value:"+36",label:"+36",sublabel:"Hungria"},{value:"+39",label:"+39",sublabel:"Italia, Vaticano"},{value:"+40",label:"+40",sublabel:"Rumania"},{value:"+41",label:"+41",sublabel:"Suiza"},{value:"+43",label:"+43",sublabel:"Austria"},{value:"+44",label:"+44",sublabel:"Reino Unido"},{value:"+45",label:"+45",sublabel:"Dinamarca"},{value:"+46",label:"+46",sublabel:"Suecia"},{value:"+47",label:"+47",sublabel:"Noruega"},{value:"+48",label:"+48",sublabel:"Polonia"},{value:"+49",label:"+49",sublabel:"Alemania"},{value:"+51",label:"+51",sublabel:"Peru"},{value:"+52",label:"+52",sublabel:"Mexico"},{value:"+53",label:"+53",sublabel:"Cuba"},{value:"+54",label:"+54",sublabel:"Argentina"},{value:"+55",label:"+55",sublabel:"Brasil"},{value:"+56",label:"+56",sublabel:"Chile"},{value:"+57",label:"+57",sublabel:"Colombia"},{value:"+58",label:"+58",sublabel:"Venezuela"},{value:"+60",label:"+60",sublabel:"Malasia"},{value:"+61",label:"+61",sublabel:"Australia"},{value:"+62",label:"+62",sublabel:"Indonesia"},{value:"+63",label:"+63",sublabel:"Filipinas"},{value:"+64",label:"+64",sublabel:"Nueva Zelanda"},{value:"+65",label:"+65",sublabel:"Singapur"},{value:"+66",label:"+66",sublabel:"Tailandia"},{value:"+81",label:"+81",sublabel:"Japon"},{value:"+82",label:"+82",sublabel:"Corea del Sur"},{value:"+84",label:"+84",sublabel:"Vietnam"},{value:"+86",label:"+86",sublabel:"China"},{value:"+90",label:"+90",sublabel:"Turquia"},{value:"+91",label:"+91",sublabel:"India"},{value:"+92",label:"+92",sublabel:"Pakistan"},{value:"+93",label:"+93",sublabel:"Afganistan"},{value:"+94",label:"+94",sublabel:"Sri Lanka"},{value:"+95",label:"+95",sublabel:"Myanmar"},{value:"+98",label:"+98",sublabel:"Iran"},{value:"+211",label:"+211",sublabel:"Sudan del Sur"},{value:"+212",label:"+212",sublabel:"Marruecos, Sahara Occidental"},{value:"+213",label:"+213",sublabel:"Argelia"},{value:"+216",label:"+216",sublabel:"Tunez"},{value:"+218",label:"+218",sublabel:"Libia"},{value:"+220",label:"+220",sublabel:"Gambia"},{value:"+221",label:"+221",sublabel:"Senegal"},{value:"+222",label:"+222",sublabel:"Mauritania"},{value:"+223",label:"+223",sublabel:"Mali"},{value:"+224",label:"+224",sublabel:"Guinea"},{value:"+225",label:"+225",sublabel:"Costa de Marfil"},{value:"+226",label:"+226",sublabel:"Burkina Faso"},{value:"+227",label:"+227",sublabel:"Niger"},{value:"+228",label:"+228",sublabel:"Togo"},{value:"+229",label:"+229",sublabel:"Benin"},{value:"+230",label:"+230",sublabel:"Mauricio"},{value:"+231",label:"+231",sublabel:"Liberia"},{value:"+232",label:"+232",sublabel:"Sierra Leona"},{value:"+233",label:"+233",sublabel:"Ghana"},{value:"+234",label:"+234",sublabel:"Nigeria"},{value:"+235",label:"+235",sublabel:"Chad"},{value:"+236",label:"+236",sublabel:"Republica Centroafricana"},{value:"+237",label:"+237",sublabel:"Camerun"},{value:"+238",label:"+238",sublabel:"Cabo Verde"},{value:"+239",label:"+239",sublabel:"Santo Tome y Principe"},{value:"+240",label:"+240",sublabel:"Guinea Ecuatorial"},{value:"+241",label:"+241",sublabel:"Gabon"},{value:"+242",label:"+242",sublabel:"Republica del Congo"},{value:"+243",label:"+243",sublabel:"Republica Democratica del Congo"},{value:"+244",label:"+244",sublabel:"Angola"},{value:"+245",label:"+245",sublabel:"Guinea-Bisau"},{value:"+246",label:"+246",sublabel:"Territorio Britanico del Oceano Indico"},{value:"+248",label:"+248",sublabel:"Seychelles"},{value:"+249",label:"+249",sublabel:"Sudan"},{value:"+250",label:"+250",sublabel:"Ruanda"},{value:"+251",label:"+251",sublabel:"Etiopia"},{value:"+252",label:"+252",sublabel:"Somalia"},{value:"+253",label:"+253",sublabel:"Yibuti"},{value:"+254",label:"+254",sublabel:"Kenia"},{value:"+255",label:"+255",sublabel:"Tanzania"},{value:"+256",label:"+256",sublabel:"Uganda"},{value:"+257",label:"+257",sublabel:"Burundi"},{value:"+258",label:"+258",sublabel:"Mozambique"},{value:"+260",label:"+260",sublabel:"Zambia"},{value:"+261",label:"+261",sublabel:"Madagascar"},{value:"+262",label:"+262",sublabel:"Reunion, Mayotte"},{value:"+263",label:"+263",sublabel:"Zimbabue"},{value:"+264",label:"+264",sublabel:"Namibia"},{value:"+265",label:"+265",sublabel:"Malaui"},{value:"+266",label:"+266",sublabel:"Lesoto"},{value:"+267",label:"+267",sublabel:"Botsuana"},{value:"+268",label:"+268",sublabel:"Esuatini"},{value:"+269",label:"+269",sublabel:"Comoras"},{value:"+290",label:"+290",sublabel:"Santa Elena"},{value:"+291",label:"+291",sublabel:"Eritrea"},{value:"+297",label:"+297",sublabel:"Aruba"},{value:"+298",label:"+298",sublabel:"Islas Feroe"},{value:"+299",label:"+299",sublabel:"Groenlandia"},{value:"+350",label:"+350",sublabel:"Gibraltar"},{value:"+351",label:"+351",sublabel:"Portugal"},{value:"+352",label:"+352",sublabel:"Luxemburgo"},{value:"+353",label:"+353",sublabel:"Irlanda"},{value:"+354",label:"+354",sublabel:"Islandia"},{value:"+355",label:"+355",sublabel:"Albania"},{value:"+356",label:"+356",sublabel:"Malta"},{value:"+357",label:"+357",sublabel:"Chipre"},{value:"+358",label:"+358",sublabel:"Finlandia, Aland"},{value:"+359",label:"+359",sublabel:"Bulgaria"},{value:"+370",label:"+370",sublabel:"Lituania"},{value:"+371",label:"+371",sublabel:"Letonia"},{value:"+372",label:"+372",sublabel:"Estonia"},{value:"+373",label:"+373",sublabel:"Moldavia"},{value:"+374",label:"+374",sublabel:"Armenia"},{value:"+375",label:"+375",sublabel:"Bielorrusia"},{value:"+376",label:"+376",sublabel:"Andorra"},{value:"+377",label:"+377",sublabel:"Monaco"},{value:"+378",label:"+378",sublabel:"San Marino"},{value:"+380",label:"+380",sublabel:"Ucrania"},{value:"+381",label:"+381",sublabel:"Serbia"},{value:"+382",label:"+382",sublabel:"Montenegro"},{value:"+383",label:"+383",sublabel:"Kosovo"},{value:"+385",label:"+385",sublabel:"Croacia"},{value:"+386",label:"+386",sublabel:"Eslovenia"},{value:"+387",label:"+387",sublabel:"Bosnia y Herzegovina"},{value:"+389",label:"+389",sublabel:"Macedonia del Norte"},{value:"+420",label:"+420",sublabel:"Chequia"},{value:"+421",label:"+421",sublabel:"Eslovaquia"},{value:"+423",label:"+423",sublabel:"Liechtenstein"},{value:"+500",label:"+500",sublabel:"Islas Malvinas"},{value:"+501",label:"+501",sublabel:"Belice"},{value:"+502",label:"+502",sublabel:"Guatemala"},{value:"+503",label:"+503",sublabel:"El Salvador"},{value:"+504",label:"+504",sublabel:"Honduras"},{value:"+505",label:"+505",sublabel:"Nicaragua"},{value:"+506",label:"+506",sublabel:"Costa Rica"},{value:"+507",label:"+507",sublabel:"Panama"},{value:"+508",label:"+508",sublabel:"San Pedro y Miquelon"},{value:"+509",label:"+509",sublabel:"Haiti"},{value:"+590",label:"+590",sublabel:"Guadalupe, San Bartolome"},{value:"+591",label:"+591",sublabel:"Bolivia"},{value:"+592",label:"+592",sublabel:"Guyana"},{value:"+593",label:"+593",sublabel:"Ecuador"},{value:"+594",label:"+594",sublabel:"Guayana Francesa"},{value:"+595",label:"+595",sublabel:"Paraguay"},{value:"+596",label:"+596",sublabel:"Martinica"},{value:"+597",label:"+597",sublabel:"Surinam"},{value:"+598",label:"+598",sublabel:"Uruguay"},{value:"+599",label:"+599",sublabel:"Caribe Neerlandes, Curazao"},{value:"+670",label:"+670",sublabel:"Timor Oriental"},{value:"+672",label:"+672",sublabel:"Antartida, Isla Norfolk"},{value:"+673",label:"+673",sublabel:"Brunei"},{value:"+674",label:"+674",sublabel:"Nauru"},{value:"+675",label:"+675",sublabel:"Papua Nueva Guinea"},{value:"+676",label:"+676",sublabel:"Tonga"},{value:"+677",label:"+677",sublabel:"Islas Salomon"},{value:"+678",label:"+678",sublabel:"Vanuatu"},{value:"+679",label:"+679",sublabel:"Fiyi"},{value:"+680",label:"+680",sublabel:"Palaos"},{value:"+681",label:"+681",sublabel:"Wallis y Futuna"},{value:"+682",label:"+682",sublabel:"Islas Cook"},{value:"+683",label:"+683",sublabel:"Niue"},{value:"+685",label:"+685",sublabel:"Samoa"},{value:"+686",label:"+686",sublabel:"Kiribati"},{value:"+687",label:"+687",sublabel:"Nueva Caledonia"},{value:"+688",label:"+688",sublabel:"Tuvalu"},{value:"+689",label:"+689",sublabel:"Polinesia Francesa"},{value:"+690",label:"+690",sublabel:"Tokelau"},{value:"+691",label:"+691",sublabel:"Micronesia"},{value:"+692",label:"+692",sublabel:"Islas Marshall"},{value:"+850",label:"+850",sublabel:"Corea del Norte"},{value:"+852",label:"+852",sublabel:"Hong Kong"},{value:"+853",label:"+853",sublabel:"Macao"},{value:"+855",label:"+855",sublabel:"Camboya"},{value:"+856",label:"+856",sublabel:"Laos"},{value:"+880",label:"+880",sublabel:"Banglades"},{value:"+886",label:"+886",sublabel:"Taiwan"},{value:"+960",label:"+960",sublabel:"Maldivas"},{value:"+961",label:"+961",sublabel:"Libano"},{value:"+962",label:"+962",sublabel:"Jordania"},{value:"+963",label:"+963",sublabel:"Siria"},{value:"+964",label:"+964",sublabel:"Irak"},{value:"+965",label:"+965",sublabel:"Kuwait"},{value:"+966",label:"+966",sublabel:"Arabia Saudita"},{value:"+967",label:"+967",sublabel:"Yemen"},{value:"+968",label:"+968",sublabel:"Oman"},{value:"+970",label:"+970",sublabel:"Palestina"},{value:"+971",label:"+971",sublabel:"Emiratos Arabes Unidos"},{value:"+972",label:"+972",sublabel:"Israel"},{value:"+973",label:"+973",sublabel:"Barein"},{value:"+974",label:"+974",sublabel:"Catar"},{value:"+975",label:"+975",sublabel:"Butan"},{value:"+976",label:"+976",sublabel:"Mongolia"},{value:"+977",label:"+977",sublabel:"Nepal"},{value:"+992",label:"+992",sublabel:"Tayikistan"},{value:"+993",label:"+993",sublabel:"Turkmenistan"},{value:"+994",label:"+994",sublabel:"Azerbaiyan"},{value:"+995",label:"+995",sublabel:"Georgia"},{value:"+996",label:"+996",sublabel:"Kirguistan"},{value:"+998",label:"+998",sublabel:"Uzbekistan"}];function Ms(e){return e==null?"":String(e)}function An(e){return e?e.startsWith("+")?e:`+${e}`:"+1"}function Ud(e){return typeof e=="number"?`${e}px`:e}function Vd({autoComplete:e="tel",inputMode:r="tel",validate:n=!0,invalidMessage:a="Ingresa un telefono valido.",errorDisplay:s="tooltip",error:l,value:i,defaultValue:c,onChange:d,countryCode:u,defaultCountryCode:m="+1",onCountryCodeChange:b,allowedCountryCodes:f,countryCodeOptions:g,countryCodePlaceholder:v="Codigo",countryCodeClassName:k="",countryCodeWidth:h=84,onPhoneValueChange:C,label:M,containerClassName:y="",helperText:x,helperDisplay:w="inline",labelAction:N,className:A="",required:T,disabled:U,floatingLabel:K,showPasswordToggle:Z,nativeValidation:L,errorTooltipLabel:Q="Error de validacion",...z}){var P;const[se,re]=o.useState(()=>Ms(c)),[R,V]=o.useState(()=>An(m)),B=o.useMemo(()=>{const ce=g??Es,he=f==null?void 0:f.map(An);return he!=null&&he.length?ce.filter(ie=>he.includes(ie.value)):ce},[f,g]),le=((P=B[0])==null?void 0:P.value)??"+1",j=B.some(ce=>ce.value===An(u??R))?An(u??R):le,W=i!==void 0?Ms(i):se,ae=`${j} ${W}`.trim(),H=n&&W.length>0&&!za(ae)?a:void 0,D=l??H,$=!!D,oe=$&&s!=="tooltip",G=$&&s!=="inline",X=!!x&&w==="tooltip"&&!oe,S=$?"border-[var(--danger)] focus-within:border-[var(--danger)]":"border-[var(--border)] focus-within:border-[var(--primary)]",O=ce=>{const he=ce.currentTarget.value;i===void 0&&re(he),C==null||C(he,{countryCode:j,nationalNumber:he,fullNumber:`${j} ${he}`.trim()}),d==null||d(ce)},I=ce=>{u===void 0&&V(ce),b==null||b(ce),C==null||C(W,{countryCode:ce,nationalNumber:W,fullNumber:`${ce} ${W}`.trim()})},te=G?t.jsx(nr,{as:"span",content:D,className:"absolute right-2.5 top-1/2 flex h-7 w-7 -translate-y-1/2 items-center justify-center rounded-md text-[var(--danger)] outline-none transition-colors hover:bg-[var(--danger-bg)] focus-visible:bg-[var(--danger-bg)]",children:t.jsx("span",{tabIndex:0,role:"img","aria-label":Q,className:"flex h-full w-full items-center justify-center outline-none",children:t.jsx(vs,{className:"h-[18px] w-[18px]"})})}):null;return t.jsxs("div",{className:`flex flex-col gap-2 ${y}`,children:[t.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-semibold uppercase text-[var(--text-muted)]",children:[t.jsx("span",{children:M}),T&&t.jsx("span",{className:"text-[var(--danger)]",children:"*"}),X?t.jsx(xr,{content:x}):null,N&&t.jsx("span",{className:"ml-auto normal-case",children:N})]}),t.jsxs("span",{className:`flex h-10 min-w-0 items-center overflow-hidden rounded-lg border bg-[var(--bg-input)] transition-colors ${S}`,children:[t.jsx(ar,{value:j,onChange:I,options:B,placeholder:v,disabled:U,ariaLabel:"Codigo telefonico",triggerVariant:"ghost",showSelectedSublabel:!1,searchable:!0,minOptionsForSearch:0,dropdownMinWidth:300,className:`shrink-0 ${k}`,style:{width:Ud(h)},height:38,padding:"0 8px 0 10px"}),t.jsx("span",{className:"h-5 w-px shrink-0 bg-[var(--border)]"}),t.jsxs("span",{className:"relative min-w-0 flex-1 self-stretch",children:[t.jsx("input",{...z,value:i,defaultValue:c,type:"tel",inputMode:r,autoComplete:e,disabled:U,required:void 0,"aria-label":z["aria-label"]??(typeof M=="string"?M:void 0),"aria-invalid":$||z["aria-invalid"],className:`h-full w-full min-w-0 bg-transparent px-2 py-1.5 text-sm text-[var(--text-main)] outline-none placeholder:text-[var(--text-muted)] disabled:cursor-not-allowed disabled:opacity-60 ${G?"pr-10":""} ${A}`,onChange:O}),te]})]}),t.jsx(wr,{error:oe?D:void 0,helperText:x,helperDisplay:w})]})}function Yd({value:e,onChange:r,options:n,name:a,label:s,orientation:l="vertical",disabled:i=!1,className:c="",optionClassName:d=""}){return t.jsxs("fieldset",{className:`min-w-0 ${c}`,disabled:i,children:[s&&t.jsx("legend",{className:"mb-2 text-xs font-semibold uppercase text-[var(--text-muted)]",children:s}),t.jsx("div",{className:l==="horizontal"?"flex flex-wrap gap-2":"flex flex-col gap-2",children:n.map(u=>{const m=u.value===e,b=i||u.disabled;return t.jsxs("label",{className:`inline-flex min-w-0 items-start gap-2 rounded-lg border px-2.5 py-1.5 transition-colors ${b?"cursor-not-allowed opacity-60":"cursor-pointer hover:bg-[var(--bg-input)]"} ${d}`,style:{borderColor:m?"color-mix(in srgb, var(--primary) 48%, var(--border))":"var(--border)",background:m?"color-mix(in srgb, var(--primary) 8%, transparent)":"var(--bg-card)"},children:[t.jsxs("span",{className:"relative mt-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full border border-[var(--border)] bg-[var(--bg-input)]",children:[t.jsx("input",{type:"radio",name:a,value:u.value,checked:m,disabled:b,onChange:()=>r(u.value),className:"absolute inset-0 opacity-0"}),t.jsx("span",{className:`h-2 w-2 rounded-full transition ${m?"scale-100 opacity-100":"scale-50 opacity-0"}`,style:{background:"var(--primary)"}})]}),t.jsxs("span",{className:"min-w-0",children:[t.jsx("span",{className:"block text-sm font-medium leading-5 text-[var(--text-main)]",children:u.label}),u.description&&t.jsx("span",{className:"block text-xs leading-5 text-[var(--text-muted)]",children:u.description})]})]},u.value)})})]})}const Xd=new Set(["table","thead","tbody","tfoot","tr","th","td","caption"]),Ln=(e,r,n)=>Math.min(n,Math.max(r,Math.round(e)||r)),Sr=12,Dn=8,Ka=(e,r,n)=>{const a=On(n),s=e.insertRow(r);for(let l=0;l<a;l+=1){const i=s.insertCell(-1);i.innerHTML="<br>"}return s.cells[0]??null},Ts=(e,r)=>{const n=e.rows[r];if(!n)return null;const a=n.parentElement;if(!a)return null;if(a.tagName==="THEAD"){const l=e.tBodies[0]??e.createTBody();return l.rows.length>=Sr?null:Ka(l,0,e)}if(a.tagName==="TBODY"&&a.rows.length>=Sr)return null;const s=Array.from(a.rows).indexOf(n);return Ka(a,s+1,e)},Kd=(e,r)=>{var s;const n=e.rows[r];if(!n)return!1;const a=n.parentElement;return(a==null?void 0:a.tagName)==="TBODY"&&a.rows.length<=1||(a==null?void 0:a.tagName)==="THEAD"&&((s=e.tBodies[0])==null?void 0:s.rows.length)===0&&e.rows.length<=1?!1:(n.remove(),!0)},$s=(e,r)=>On(e)>=Dn?!1:(e.querySelectorAll("tr").forEach(n=>{const a=n.closest("thead")!==null,s=document.createElement(a?"th":"td");a?s.textContent=`Columna ${n.cells.length+1}`:s.innerHTML="<br>";const l=n.cells[r];l!=null&&l.nextSibling?n.insertBefore(s,l.nextSibling):n.appendChild(s)}),!0),Gd=(e,r)=>On(e)<=1?!1:(e.querySelectorAll("tr").forEach(n=>{var a;(a=n.cells[r])==null||a.remove()}),!0),As=e=>{e.querySelectorAll(".rich-table-row-active").forEach(r=>{r.classList.remove("rich-table-row-active")}),e.querySelectorAll(".rich-table-col-active").forEach(r=>{r.classList.remove("rich-table-col-active")})},Ls=(e,r,n)=>{As(e),r&&(r.classList.add("rich-table-row-active"),e.querySelectorAll("tr").forEach(a=>{var s;(s=a.cells[n])==null||s.classList.add("rich-table-col-active")}))},Zd=(e,r,n)=>{const a=e.getBoundingClientRect();return{rowIndex:Array.from(e.rows).indexOf(r),colIndex:n.cellIndex,bar:{x:a.left+a.width/2,y:a.top-6}}},In=e=>{const r=e.cloneNode(!0);return r.querySelectorAll(".rich-table-ui").forEach(n=>n.remove()),r.querySelectorAll(".rich-table-wrap").forEach(n=>{const a=n.querySelector("table");a?n.replaceWith(a):n.remove()}),r.querySelectorAll("table").forEach(n=>{n.classList.add("rich-table")}),r.querySelectorAll(".rich-table-row-active, .rich-table-col-active").forEach(n=>{n.classList.remove("rich-table-row-active","rich-table-col-active")}),r.innerHTML},Ds=e=>{e.querySelectorAll(".rich-table-wrap").forEach(r=>{const n=r.querySelector("table");n&&r.replaceWith(n)}),e.querySelectorAll(".rich-table-ui").forEach(r=>r.remove()),e.querySelectorAll("table").forEach(r=>{r.classList.add("rich-table")})},Qd=(e,r,n,a,s)=>{switch(e){case"table-delete":return r.remove(),!0;case"table-row-add":{const l=Number.isFinite(n)?Ts(r,n):Ga(r);return l&&Hn(l,s,!0),!!l}case"table-row-del":return Number.isFinite(n)?Kd(r,n):!1;case"table-col-add":return Number.isFinite(a)?$s(r,a):tu(r);case"table-col-del":return Number.isFinite(a)?Gd(r,a):!1;default:return!1}},On=e=>{let r=0;return e.querySelectorAll("tr").forEach(n=>{r=Math.max(r,n.cells.length)}),r||1},Jd=e=>{const r=e.tBodies[0]??e.createTBody();return Array.from(r.rows)},Is=e=>(e==null?void 0:e.closest("table"))??null,Os=e=>{if(!e)return null;const r=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return(r==null?void 0:r.closest("td, th"))??null},Rd=e=>Array.from(e.querySelectorAll("th, td")),Hs=(e,r)=>{if(e.closest("thead"))return!1;const n=e.closest("tbody")??r.tBodies[0];if(!n)return!1;const a=Array.from(n.rows),s=e.closest("tr");return!s||s!==a[a.length-1]?!1:e===s.cells[s.cells.length-1]},eu=e=>{const r=window.getSelection();if(!r||!r.isCollapsed||r.rangeCount===0)return!1;const n=r.getRangeAt(0);if(!e.contains(n.startContainer))return!1;const a=n.cloneRange();return a.selectNodeContents(e),a.setStart(n.endContainer,n.endOffset),a.toString().trim()===""},Hn=(e,r,n=!0)=>{r==null||r.focus();const a=document.createRange();a.selectNodeContents(e),a.collapse(n);const s=window.getSelection();s==null||s.removeAllRanges(),s==null||s.addRange(a)},Ga=e=>{const r=Jd(e);if(r.length>=Sr)return null;const n=r[r.length-1];if(!n){const a=e.tBodies[0]??e.createTBody();return Ka(a,0,e)}return Ts(e,Array.from(e.rows).indexOf(n))},tu=e=>{const r=On(e)-1;return r<0?!1:$s(e,r)},Za=e=>{Ds(e)},ru=(e,r,n)=>{const a=Ln(e,1,Sr),s=Ln(r,1,Dn),l=n?`<thead><tr>${Array.from({length:s},(c,d)=>`<th>Columna ${d+1}</th>`).join("")}</tr></thead>`:"",i=Array.from({length:a},()=>`<tr>${Array.from({length:s},()=>"<td><br></td>").join("")}</tr>`).join("");return`<table class="rich-table">${l}<tbody>${i}</tbody></table><p><br></p>`},Bs=()=>'<button type="button" class="rich-img-del" data-action="delete-img" title="Eliminar imagen"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M9 2a1 1 0 0 0-.894.553L7.382 4H4a1 1 0 0 0 0 2v10a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V6a1 1 0 0 0 0-2h-3.382l-.724-1.447A1 1 0 0 0 11 2H9zm-1 6a1 1 0 1 1 2 0v4a1 1 0 1 1-2 0V8zm4 0a1 1 0 1 1 2 0v4a1 1 0 1 1-2 0V8z" clip-rule="evenodd"/></svg></button>',en=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),Fs=e=>e.toLocaleLowerCase().replace(new RegExp("(^|[^\\p{L}\\p{N}])(\\p{L})","gu"),(r,n,a)=>`${n}${a.toLocaleUpperCase()}`),nu=e=>e.replace(/[<>]/g,"").toLowerCase(),au=new Set(["p","br","div","span","b","strong","i","em","u","s","strike","ul","ol","li","h1","h2","h3","h4","blockquote","a","img","hr","table","thead","tbody","tfoot","tr","th","td","caption"]),ou=/^[\s\u00a0]*([•●○■▪▫◆◇►▶➢❖✓✔\-–—*])[\s\u00a0]+/,su=e=>{const r=e.indexOf("<!--StartFragment-->"),n=e.indexOf("<!--EndFragment-->");if(r!==-1&&n!==-1&&n>r)return e.slice(r+20,n);const a=e.match(/<body[^>]*>([\s\S]*)<\/body>/i);return a?a[1]:e},Bn=(e,r)=>r.test(e),lu=e=>Bn(e,/font-weight\s*:\s*(bold|[6-9]00)/i),iu=e=>Bn(e,/font-style\s*:\s*italic/i),cu=e=>Bn(e,/text-decoration(?:-line)?\s*:[^;]*underline/i),du=e=>Bn(e,/text-decoration(?:-line)?\s*:[^;]*(line-through|linethrough)/i),Fn=(e,r)=>{var a;if(!e.childNodes.length||e.childNodes.length===1&&((a=e.firstChild)==null?void 0:a.nodeType)===Node.ELEMENT_NODE&&e.firstChild.tagName.toLowerCase()===r)return;const n=e.ownerDocument.createElement(r);for(;e.firstChild;)n.appendChild(e.firstChild);e.appendChild(n)},Pn=e=>{const r=e.parentNode;if(!r){e.remove();return}for(;e.firstChild;)r.insertBefore(e.firstChild,e);r.removeChild(e)},uu=e=>{const r=e.getAttribute("class")??"",n=e.getAttribute("style")??"";return/mso-list/i.test(n)||/MsoListParagraph/i.test(r)||/MsoList/i.test(r)},Ps=e=>{const r=e.getAttribute("style")??"",n=e.textContent??"";return/mso-level-number-format\s*:\s*(decimal|arabic|roman|alpha)/i.test(r)||/^\s*\d+[.)]\s/.test(n)||/^\s*[a-zA-Z][.)]\s/.test(n)?"ol":"ul"},fu=e=>{const n=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT).nextNode();if(!n||!n.textContent)return;const a=n.textContent.replace(ou,"").replace(/^\s*\d+[.)]\s+/,"").replace(/^\s*[a-zA-Z][.)]\s+/,"");a!==n.textContent&&(n.textContent=a)},bu=e=>{const r=Array.from(e.querySelectorAll("span, font, p, div, li, h1, h2, h3, h4"));r.sort((n,a)=>a.querySelectorAll("*").length-n.querySelectorAll("*").length),r.forEach(n=>{const a=n.getAttribute("style")??"";a&&(lu(a)&&Fn(n,"strong"),iu(a)&&Fn(n,"em"),cu(a)&&Fn(n,"u"),du(a)&&Fn(n,"s"))})},mu=e=>{const r=Array.from(e.querySelectorAll("p, div")).filter(uu);if(!r.length)return;let n=0;for(;n<r.length;){const a=r[n],s=Ps(a),l=[a];let i=n+1;for(;i<r.length;){const u=r[i];if(Ps(u)!==s)break;let m=l[l.length-1].nextSibling;for(;m&&m.nodeType===Node.TEXT_NODE&&!(m.textContent??"").trim();)m=m.nextSibling;if(m!==u)break;l.push(u),i++}const c=a.parentNode;if(!c){n=i;continue}const d=a.ownerDocument.createElement(s);c.insertBefore(d,a),l.forEach(u=>{fu(u);const m=u.ownerDocument.createElement("li");for(;u.firstChild;)m.appendChild(u.firstChild);d.appendChild(m),u.remove()}),n=i}},pu=e=>e==="h1"?"h2":e==="h4"||e==="h5"||e==="h6"?"h3":e==="div"?"p":e,hu=e=>{const r=su(e.replace(/<!--\[if[\s\S]*?<!\[endif\]-->/gi,"").replace(/<xml[\s\S]*?<\/xml>/gi,"").replace(/<style[\s\S]*?<\/style>/gi,"").replace(/<\/?o:[^>]*>/gi,"").replace(/<\/?w:[^>]*>/gi,"").replace(/<\/?m:[^>]*>/gi,"")),s=new DOMParser().parseFromString(`<!DOCTYPE html><html><body>${r}</body></html>`,"text/html").body;s.querySelectorAll("script, style, meta, link, xml, title, head, iframe, object, embed, form, input, button, textarea, select, noscript").forEach(i=>i.remove()),bu(s),mu(s);const l=i=>{const c=Array.from(i.childNodes);if(i.nodeType===Node.ELEMENT_NODE){const d=i,u=d.tagName.toLowerCase();if(u==="html"||u==="body"){c.forEach(l);return}if(u==="font"){Pn(d),c.forEach(l);return}if(!au.has(u)){Pn(d),c.forEach(l);return}if(u==="div"){const b=d.getAttribute("class")??"";if(/rich-table-wrap/.test(b)){Array.from(d.attributes).forEach(f=>{f.name.toLowerCase()!=="class"&&d.removeAttribute(f.name)}),d.className="rich-table-wrap",c.forEach(l);return}}const m=pu(u);if(m!==u){const b=d.ownerDocument.createElement(m);for(;d.firstChild;)b.appendChild(d.firstChild);d.replaceWith(b),l(b);return}if(Xd.has(u)){Array.from(d.attributes).forEach(b=>{const f=b.name.toLowerCase();if(u==="td"||u==="th"){["colspan","rowspan"].includes(f)||d.removeAttribute(b.name);return}d.removeAttribute(b.name)}),u==="table"&&d.classList.add("rich-table"),c.forEach(l);return}if(Array.from(d.attributes).forEach(b=>{const f=b.name.toLowerCase(),g=b.value;if(f.startsWith("on")||f==="style"||f==="class"){d.removeAttribute(b.name);return}if(f==="lang"||f.startsWith("data-")||f.startsWith("mso-")){d.removeAttribute(b.name);return}if((f==="href"||f==="src")&&/^\s*javascript:/i.test(g)){d.removeAttribute(b.name);return}u!=="a"&&u!=="img"&&f!=="href"&&f!=="src"&&f!=="alt"&&(["href","src","alt","target","rel"].includes(f)||d.removeAttribute(b.name))}),u==="a"){const b=d.getAttribute("href");if(!b||/^\s*#/.test(b)&&b.length<2){Pn(d),c.forEach(l);return}d.setAttribute("target","_blank"),d.setAttribute("rel","noopener noreferrer"),d.classList.add("rich-link")}if(u==="img"){const b=d.getAttribute("src")??"";if(!b||/^\s*javascript:/i.test(b)||/^file:/i.test(b)||/scheme\s*=\s*["']?file/i.test(b)){d.remove();return}d.classList.add("rich-img"),Array.from(d.attributes).forEach(f=>{["src","alt","class"].includes(f.name.toLowerCase())||d.removeAttribute(f.name)})}if(u==="span"){Pn(d),c.forEach(l);return}}c.forEach(l)};return l(s),s.querySelectorAll("p, h2, h3, li").forEach(i=>{const c=(i.textContent??"").replace(/[\u00a0\s]+/g,"").trim(),d=i.querySelector("img, hr"),u=!c&&!d&&Array.from(i.childNodes).every(m=>m.nodeType===Node.TEXT_NODE||m.nodeType===Node.ELEMENT_NODE&&m.tagName.toLowerCase()==="br");(!c&&!d||u)&&i.remove()}),s.querySelectorAll("strong, b, em, i, u, s").forEach(i=>{let c=i.nextSibling;for(;c&&c.nodeType===Node.TEXT_NODE&&!(c.textContent??"").trim();)c=c.nextSibling;if(c&&c.nodeType===Node.ELEMENT_NODE&&c.tagName===i.tagName){const d=c;for(;d.firstChild;)i.appendChild(d.firstChild);d.remove()}}),s.innerHTML.replace(/<!--[\s\S]*?-->/g,"").replace(/&nbsp;/gi," ").replace(/(<br\s*\/?>\s*){3,}/gi,"<br><br>").replace(/<p>(?:\s|<br\s*\/?>)*<\/p>/gi,"").trim()},Qa=e=>en(e).replace(/\r\n?/g,`
25
- `).split(/\n{2,}/).map(r=>`<p>${r.replace(/\n/g,"<br>")||"<br>"}</p>`).join(""),gu=e=>new RegExp("\\p{L}","u").test(e),Ja=(e,r)=>{const n=e.trim();return!n||!gu(n)?!1:r==="uppercase"?n===n.toLocaleUpperCase():r==="lowercase"?n===n.toLocaleLowerCase():n===Fs(n)},_s=e=>{const r=a=>{var s,l;if(!a.closest(".rich-img-wrap")){const i=document.createElement("span");i.className="rich-img-wrap",i.contentEditable="false",(s=a.parentNode)==null||s.insertBefore(i,a),i.appendChild(a),i.insertAdjacentHTML("beforeend",Bs())}(l=a.closest(".rich-img-wrap"))==null||l.classList.add("rich-img-broken")};e.querySelectorAll("img").forEach(a=>{if(!a.complete||a.naturalWidth===0){a.addEventListener("error",()=>r(a),{once:!0}),a.addEventListener("load",()=>{a.naturalWidth===0&&r(a)},{once:!0});const s=a.src;a.src="",a.src=s}});const n=a=>{const s=a.target;s.tagName==="IMG"&&r(s)};return e.addEventListener("error",n,!0),()=>e.removeEventListener("error",n,!0)};function zs({value:e,onChange:r,placeholder:n="Escribe algo...",minHeight:a="80px",instanceId:s}){const l=o.useId(),i=s||l,c=o.useCallback(()=>document,[]),d=o.useRef(null),u=o.useRef(null),m=o.useRef(new Map),b=o.useRef(null),f=o.useRef(!1),g=o.useRef(e??""),v=o.useRef(r),k=o.useRef(()=>{}),h=o.useRef(!1),[C,M]=o.useState(()=>!e||e.trim()===""),[y,x]=o.useState(new Set),[w,N]=o.useState(null),[A,T]=o.useState(""),[U,K]=o.useState(""),[Z,L]=o.useState(""),[Q,z]=o.useState(""),[se,re]=o.useState(3),[R,V]=o.useState(3),[B,le]=o.useState(!0),[j,W]=o.useState(!1),[ae,H]=o.useState(null),[D,$]=o.useState(null),oe=o.useRef(null),G=o.useRef(!1),X=o.useRef(null),S=o.useCallback(()=>f.current?u.current:d.current,[]);o.useEffect(()=>{v.current=r},[r]);const O=o.useCallback(()=>{const _=window.getSelection(),J=S();if(!_||!J||_.rangeCount===0||_.isCollapsed)return"";const ue=_.getRangeAt(0);return!J.contains(ue.startContainer)||!J.contains(ue.endContainer)?"":_.toString()},[S]);o.useEffect(()=>{const _=e??"";if(h.current&&_===g.current){h.current=!1,M(!_||_.trim()==="");return}h.current=!1,g.current=_;const J=[d.current,u.current].filter(fe=>!!fe);J.forEach(fe=>{fe.innerHTML!==_&&(fe.innerHTML=_)}),M(!_||_.trim()===""),J.forEach(fe=>Za(fe));const ue=J.map(fe=>_s(fe));return()=>ue.forEach(fe=>fe())},[e]),o.useEffect(()=>{var fe,$e;f.current=j;let _,J=0,ue;if(j){const xe=d.current;xe&&(g.current=In(xe));const De=()=>{var ot;const Ie=u.current;if(!Ie){J=requestAnimationFrame(De);return}Ie.innerHTML!==g.current&&(Ie.innerHTML=g.current),_=_s(Ie),Za(Ie),M(((ot=Ie.textContent)==null?void 0:ot.trim())===""),ue=setTimeout(()=>Ie.focus(),60)};J=requestAnimationFrame(De)}else{const xe=u.current,De=d.current,Ie=xe?In(xe):g.current,ot=g.current;g.current=Ie,De&&De.innerHTML!==Ie&&(De.innerHTML=Ie),Ie!==ot&&v.current(Ie),M((($e=(fe=xe??De)==null?void 0:fe.textContent)==null?void 0:$e.trim())==="")}return()=>{J&&cancelAnimationFrame(J),ue&&clearTimeout(ue),_==null||_()}},[j]);const I=o.useCallback(()=>{const _=["bold","italic","underline","strikeThrough","insertUnorderedList","insertOrderedList","justifyLeft","justifyCenter","justifyRight","justifyFull"],J=new Set;_.forEach(fe=>{try{c().queryCommandState(fe)&&J.add(fe)}catch{return}});try{const fe=nu(c().queryCommandValue("formatBlock"));fe&&J.add(`formatBlock:${fe}`)}catch{}const ue=O();Ja(ue,"uppercase")&&J.add("__upper"),Ja(ue,"lowercase")&&J.add("__lower"),Ja(ue,"capitalize")&&J.add("__cap"),x(J)},[O,c]),te=()=>{var J;const _=S();_&&(g.current=In(_),h.current=!0,v.current(g.current),M(((J=_.textContent)==null?void 0:J.trim())===""))};k.current=te;const P=o.useCallback(()=>{X.current&&(clearTimeout(X.current),X.current=null),oe.current&&(As(oe.current),oe.current=null),G.current=!1,H(null),$(null)},[]),ce=o.useCallback(()=>{X.current&&(clearTimeout(X.current),X.current=null)},[]),he=o.useCallback(()=>{ce(),X.current=setTimeout(()=>{G.current||P()},280)},[ce,P]);o.useEffect(()=>()=>{X.current&&clearTimeout(X.current)},[]);const ie=o.useCallback(_=>{const J=oe.current;if(!J||!J.isConnected){P();return}const ue=(ae==null?void 0:ae.rowIndex)??(D==null?void 0:D.rowIndex)??-1,fe=(ae==null?void 0:ae.colIndex)??(D==null?void 0:D.colIndex)??-1;Qd(_,J,ue,fe,S()),P(),k.current(),I()},[S,P,I,D,ae]),ge=o.useCallback(_=>{if(D)return;const J=_.currentTarget,ue=_.target;if(ue.closest(".rich-table-action-bar, .rich-table-context-menu")){ce();return}const fe=ue.closest("td, th");if(!fe||!J.contains(fe)){he();return}const $e=fe.closest("tr"),xe=fe.closest("table");if(!$e||!xe||!J.contains(xe)){he();return}ce(),xe.classList.add("rich-table"),oe.current=xe,Ls(xe,$e,fe.cellIndex),H(Zd(xe,$e,fe))},[ce,he,D]),Te=o.useCallback(_=>{const J=_.relatedTarget;if(J instanceof Element&&(J.closest(".rich-table-action-bar")||J.closest(".rich-table-context-menu"))){ce();return}he()},[ce,he]),Le=o.useCallback(_=>{const J=_.currentTarget,fe=_.target.closest("td, th");if(!fe||!J.contains(fe))return;const $e=fe.closest("tr"),xe=fe.closest("table");if(!$e||!xe||!J.contains(xe))return;_.preventDefault(),xe.classList.add("rich-table"),oe.current=xe;const De=Array.from(xe.rows).indexOf($e),Ie=fe.cellIndex;Ls(xe,$e,Ie),H(null),$({x:_.clientX,y:_.clientY,rowIndex:De,colIndex:Ie})},[]);o.useEffect(()=>{if(!ae&&!D)return;const _=()=>he();return window.addEventListener("scroll",_,!0),window.addEventListener("resize",_),()=>{window.removeEventListener("scroll",_,!0),window.removeEventListener("resize",_)}},[he,D,ae]),o.useEffect(()=>{if(!D)return;const _=J=>{const ue=J.target;ue instanceof Element&&ue.closest(".rich-table-context-menu")||$(null)};return window.addEventListener("mousedown",_),()=>window.removeEventListener("mousedown",_)},[D]);const It=_=>{if(!_){const J=d.current;J&&(g.current=In(J))}W(!_)},ft=(_,J)=>{var ue;(ue=S())==null||ue.focus(),c().execCommand(_,!1,J),te(),I()},Qe=_=>{ft("formatBlock",_)},Ot=()=>{var _;(_=S())==null||_.focus(),c().execCommand("insertHTML",!1,"<hr><p><br></p>"),te(),I()},Se=()=>{const _=window.getSelection();_&&_.rangeCount>0&&(b.current=_.getRangeAt(0).cloneRange())},lt=()=>{const _=window.getSelection();_&&b.current&&(_.removeAllRanges(),_.addRange(b.current))},me=_=>{if(Se(),_==="link"){const J=window.getSelection();K(J&&!J.isCollapsed?J.toString():""),T("")}_==="image"&&(L(""),z("")),_==="table"&&(re(3),V(3),le(!0)),N(_)},Ye=()=>{var fe;if(!A.trim())return;lt(),(fe=S())==null||fe.focus();const _=window.getSelection(),ue=(_&&!_.isCollapsed?_.toString():"")||U.trim()||A.trim();c().execCommand("insertHTML",!1,`<a href="${en(A.trim())}" target="_blank" rel="noopener noreferrer" class="rich-link">${en(ue)}</a>`),te(),N(null)},qe=(_,J="")=>`<span class="rich-img-wrap" contenteditable="false"><img src="${en(_)}" alt="${en(J)}" class="rich-img" />${Bs()}</span>`,ct=()=>{var _;Z.trim()&&(lt(),(_=S())==null||_.focus(),c().execCommand("insertHTML",!1,qe(Z.trim(),Q.trim())),te(),N(null))},ze=()=>{var _;lt(),(_=S())==null||_.focus(),c().execCommand("insertHTML",!1,ru(se,R,B)),te(),N(null)},bt=(_,J=1200,ue=1200,fe=.72)=>new Promise(($e,xe)=>{const De=new FileReader;De.onerror=xe,De.onload=Ie=>{var ht;const ot=(ht=Ie.target)==null?void 0:ht.result,We=new Image;We.onerror=xe,We.onload=()=>{let{width:zt,height:gt}=We;if(zt>J||gt>ue){const Qt=Math.min(J/zt,ue/gt);zt=Math.round(zt*Qt),gt=Math.round(gt*Qt)}const lr=document.createElement("canvas");lr.width=zt,lr.height=gt;const Wt=lr.getContext("2d");if(!Wt){$e(ot);return}Wt.drawImage(We,0,0,zt,gt),$e(lr.toDataURL("image/jpeg",fe))},We.src=ot},De.readAsDataURL(_)}),mt=_=>{_.focus();const J=window.getSelection();if(!J||J.rangeCount===0||!_.contains(J.anchorNode)){const ue=document.createRange();ue.selectNodeContents(_),ue.collapse(!1),J==null||J.removeAllRanges(),J==null||J.addRange(ue)}},et=o.useRef(()=>{});et.current=_=>{const J=S();J&&(mt(J),c().execCommand("insertHTML",!1,_),Za(J),J.querySelectorAll("p").forEach(ue=>{!(ue.textContent??"").replace(/[\u00a0\s]+/g,"")&&!ue.querySelector("img, hr, table")&&ue.remove()}),te(),I())};const Kt=o.useRef(bt);Kt.current=bt;const de=o.useRef(qe);de.current=qe;const pe=o.useCallback(_=>{if(!_||m.current.has(_))return;const J=ue=>{const fe=ue.clipboardData;if(!fe)return;const $e=fe.getData("text/html"),xe=fe.getData("text/plain");if($e||xe){ue.preventDefault(),ue.stopPropagation();try{const We=$e?hu($e):Qa(xe);if(!We){xe&&et.current(Qa(xe));return}et.current(We)}catch{xe&&et.current(Qa(xe))}return}const Ie=Array.from(fe.items).find(We=>We.type.startsWith("image/"));if(!Ie)return;ue.preventDefault(),ue.stopPropagation();const ot=Ie.getAsFile();ot&&Kt.current(ot).then(We=>{et.current(de.current(We,"imagen"))})};_.addEventListener("paste",J,!0),m.current.set(_,()=>{_.removeEventListener("paste",J,!0),m.current.delete(_)})},[]),Me=o.useCallback(_=>{var ue;const J=d.current;J&&J!==_&&((ue=m.current.get(J))==null||ue()),d.current=_,_&&pe(_)},[pe]),Pe=o.useCallback(_=>{var ue;const J=u.current;J&&J!==_&&((ue=m.current.get(J))==null||ue()),u.current=_,_&&pe(_)},[pe]);o.useEffect(()=>{const _=m.current;return()=>{_.forEach(J=>J()),_.clear()}},[]);const Be=_=>{const J=window.getSelection(),ue=S();if(!J||!ue||J.rangeCount===0||J.isCollapsed)return;const fe=J.getRangeAt(0);if(!ue.contains(fe.startContainer)||!ue.contains(fe.endContainer))return;const $e=fe.toString();if(!$e)return;let xe=$e;_==="uppercase"?xe=$e.toLocaleUpperCase():_==="lowercase"?xe=$e.toLocaleLowerCase():xe=Fs($e),fe.deleteContents();const De=document.createTextNode(xe);fe.insertNode(De);const Ie=document.createRange();Ie.setStart(De,0),Ie.setEnd(De,xe.length),J.removeAllRanges(),J.addRange(Ie),b.current=Ie.cloneRange(),te(),I()},Fe=()=>{Se(),I()},tt=()=>{const _=S();_&&Ds(_),te(),I()},rt=()=>{requestAnimationFrame(()=>{var _;(_=S())==null||_.focus()})},Ke=_=>{var J,ue;if((_.metaKey||_.ctrlKey)&&_.key==="Enter"){if(_.preventDefault(),_.stopPropagation(),_.repeat)return;(J=S())==null||J.focus(),c().execCommand("insertLineBreak",!1)||c().execCommand("insertHTML",!1,"<br>"),te(),I();return}if(_.key==="Tab"){const fe=window.getSelection(),$e=Os((fe==null?void 0:fe.anchorNode)??null),xe=S(),De=Is($e);if($e&&De&&(xe!=null&&xe.contains($e))){_.preventDefault();const Ie=Rd(De),ot=Ie.indexOf($e),We=ot>=0?Ie[ot+1]:null;if(We)Hn(We,xe,!0);else if(Hs($e,De)){const ht=Ga(De);ht&&Hn(ht,xe,!0)}te(),I();return}_.preventDefault(),(ue=S())==null||ue.focus(),c().execCommand("insertText",!1,"    "),te(),I();return}if(_.key==="Enter"&&!_.shiftKey&&!(_.metaKey||_.ctrlKey)){const fe=window.getSelection(),$e=Os((fe==null?void 0:fe.anchorNode)??null),xe=S(),De=Is($e);if($e&&De&&(xe!=null&&xe.contains($e))&&Hs($e,De)&&eu($e)){_.preventDefault();const Ie=Ga(De);Ie&&Hn(Ie,xe,!0),te(),I();return}}if(_.key==="Escape"){if(D){$(null);return}if(w){N(null);return}if(f.current){W(!1);return}}w||(_.ctrlKey||_.metaKey)&&(_.key==="b"&&(_.preventDefault(),ft("bold")),_.key==="i"&&(_.preventDefault(),ft("italic")),_.key==="u"&&(_.preventDefault(),ft("underline")),_.key==="k"&&(_.preventDefault(),me("link")))},nt=()=>t.jsx("div",{className:"h-4 w-px flex-shrink-0 mx-1",style:{background:"var(--border)"}}),Oe=(_,J,ue,fe,$e)=>{const xe=$e??(y.has(ue)||ue==="__link"&&w==="link"||ue==="__img"&&w==="image"||ue==="__table"&&w==="table");return t.jsx("button",{type:"button",title:J,tabIndex:-1,onFocus:rt,onMouseDown:De=>{De.preventDefault(),fe?fe():ft(ue)},className:"flex h-7 w-7 items-center justify-center rounded text-xs font-bold transition-colors",style:{color:xe?"var(--primary)":"var(--text-secondary)",background:xe?"rgba(59,130,246,0.12)":"transparent"},children:_},ue)},Ht=_=>{const J=_.target;if(J.closest("[data-action='delete-img']")){_.preventDefault();const ue=J.closest(".rich-img-wrap");ue&&(ue.remove(),te())}},ta=()=>{ce(),G.current=!0},ra=()=>{G.current=!1,he()},at=(_,J,ue,fe=!1)=>t.jsx("button",{type:"button",className:`rich-table-action-btn${fe?" rich-table-action-btn--danger":""}`,title:_,"aria-label":_,onMouseDown:$e=>{$e.preventDefault(),$e.stopPropagation(),ie(ue)},children:J}),Gt=()=>typeof document>"u"||!ae&&!D?null:dt.createPortal(t.jsxs(t.Fragment,{children:[ae&&!D&&t.jsxs("div",{className:"rich-table-action-bar",style:{left:ae.bar.x,top:ae.bar.y},onMouseEnter:ta,onMouseLeave:ra,children:[t.jsxs("span",{className:"rich-table-action-hint",children:["Fila ",ae.rowIndex+1," · Col ",ae.colIndex+1]}),t.jsxs("div",{className:"rich-table-action-group",children:[t.jsx("span",{className:"rich-table-action-label",children:"Fila"}),at("Añadir fila abajo","+","table-row-add"),at("Eliminar fila","−","table-row-del")]}),t.jsxs("div",{className:"rich-table-action-group",children:[t.jsx("span",{className:"rich-table-action-label",children:"Columna"}),at("Añadir columna a la derecha","+","table-col-add"),at("Eliminar columna","−","table-col-del")]}),at("Eliminar tabla","Eliminar","table-delete",!0)]}),D&&t.jsx("div",{className:"rich-table-context-menu",style:{left:D.x,top:D.y},onMouseDown:_=>_.stopPropagation(),children:[["Añadir fila abajo","table-row-add"],["Eliminar fila","table-row-del"],["Añadir columna a la derecha","table-col-add"],["Eliminar columna","table-col-del"],["Eliminar tabla","table-delete"]].map(([_,J])=>t.jsx("button",{type:"button",onMouseDown:ue=>{ue.preventDefault(),ie(J)},children:_},J))})]}),document.body),pt=_=>t.jsxs(t.Fragment,{children:[w==="link"&&t.jsxs("div",{className:"flex flex-shrink-0 flex-wrap items-center gap-2 border-t px-3 py-2",style:{borderColor:"var(--border)",background:_},children:[t.jsx("input",{autoFocus:!0,type:"url",value:A,onChange:J=>T(J.target.value),onKeyDown:J=>{J.key==="Enter"&&(J.preventDefault(),Ye()),J.key==="Escape"&&N(null)},placeholder:"https://...",className:"min-w-0 flex-1 rounded px-2 py-1 text-xs focus:outline-none",style:{background:"var(--bg-card)",border:"1px solid var(--border)",color:"var(--text-main)"}}),t.jsx("input",{type:"text",value:U,onChange:J=>K(J.target.value),onKeyDown:J=>{J.key==="Enter"&&(J.preventDefault(),Ye()),J.key==="Escape"&&N(null)},placeholder:"Texto (opcional)",className:"w-32 rounded px-2 py-1 text-xs focus:outline-none",style:{background:"var(--bg-card)",border:"1px solid var(--border)",color:"var(--text-main)"}}),t.jsx("button",{type:"button",onClick:Ye,className:"rounded px-2.5 py-1 text-xs font-semibold text-white",style:{background:"var(--primary)"},children:"OK"}),t.jsx("button",{type:"button",onClick:()=>N(null),className:"rounded px-2 py-1 text-xs",style:{color:"var(--text-muted)"},children:"x"})]}),w==="table"&&t.jsxs("div",{className:"flex flex-shrink-0 flex-wrap items-center gap-2 border-t px-3 py-2",style:{borderColor:"var(--border)",background:_},children:[t.jsxs("label",{className:"flex items-center gap-1 text-xs",style:{color:"var(--text-secondary)"},children:["Filas",t.jsx("input",{autoFocus:!0,type:"number",min:1,max:Sr,value:se,onChange:J=>re(Ln(Number(J.target.value),1,Sr)),onKeyDown:J=>{J.key==="Enter"&&(J.preventDefault(),ze()),J.key==="Escape"&&N(null)},className:"w-14 rounded px-2 py-1 text-xs focus:outline-none",style:{background:"var(--bg-card)",border:"1px solid var(--border)",color:"var(--text-main)"}})]}),t.jsxs("label",{className:"flex items-center gap-1 text-xs",style:{color:"var(--text-secondary)"},children:["Columnas",t.jsx("input",{type:"number",min:1,max:Dn,value:R,onChange:J=>V(Ln(Number(J.target.value),1,Dn)),onKeyDown:J=>{J.key==="Enter"&&(J.preventDefault(),ze()),J.key==="Escape"&&N(null)},className:"w-14 rounded px-2 py-1 text-xs focus:outline-none",style:{background:"var(--bg-card)",border:"1px solid var(--border)",color:"var(--text-main)"}})]}),t.jsxs("label",{className:"flex items-center gap-1.5 text-xs",style:{color:"var(--text-secondary)"},children:[t.jsx("input",{type:"checkbox",checked:B,onChange:J=>le(J.target.checked)}),"Encabezado"]}),t.jsx("button",{type:"button",onClick:ze,className:"rounded px-2.5 py-1 text-xs font-semibold text-white",style:{background:"var(--primary)"},children:"OK"}),t.jsx("button",{type:"button",onClick:()=>N(null),className:"rounded px-2 py-1 text-xs",style:{color:"var(--text-muted)"},children:"x"})]}),w==="image"&&t.jsxs("div",{className:"flex flex-shrink-0 flex-wrap items-center gap-2 border-t px-3 py-2",style:{borderColor:"var(--border)",background:_},children:[t.jsx("input",{autoFocus:!0,type:"url",value:Z,onChange:J=>L(J.target.value),onKeyDown:J=>{J.key==="Enter"&&(J.preventDefault(),ct()),J.key==="Escape"&&N(null)},placeholder:"URL de la imagen...",className:"min-w-0 flex-1 rounded px-2 py-1 text-xs focus:outline-none",style:{background:"var(--bg-card)",border:"1px solid var(--border)",color:"var(--text-main)"}}),t.jsx("input",{type:"text",value:Q,onChange:J=>z(J.target.value),onKeyDown:J=>{J.key==="Enter"&&(J.preventDefault(),ct()),J.key==="Escape"&&N(null)},placeholder:"Texto alt",className:"w-28 rounded px-2 py-1 text-xs focus:outline-none",style:{background:"var(--bg-card)",border:"1px solid var(--border)",color:"var(--text-main)"}}),t.jsx("button",{type:"button",onClick:ct,className:"rounded px-2.5 py-1 text-xs font-semibold text-white",style:{background:"var(--primary)"},children:"OK"}),t.jsx("button",{type:"button",onClick:()=>N(null),className:"rounded px-2 py-1 text-xs",style:{color:"var(--text-muted)"},children:"x"})]})]}),Zt=(_,J)=>t.jsxs("div",{className:"flex flex-shrink-0 flex-wrap items-center gap-0.5 border-t px-2 py-1",style:{borderColor:"var(--border)",background:J},children:[Oe(t.jsx(q.HiArrowUturnLeft,{className:"h-4 w-4"}),"Deshacer","undo"),Oe(t.jsx(q.HiArrowUturnRight,{className:"h-4 w-4"}),"Rehacer","redo"),nt(),Oe(t.jsx("span",{style:{fontSize:"10px"},children:"P"}),"Parrafo","__paragraph",()=>Qe("p"),y.has("formatBlock:p")||y.has("formatBlock:div")),Oe(t.jsx(q.HiH2,{className:"h-4 w-4"}),"Titulo 2","__h2",()=>Qe("h2"),y.has("formatBlock:h2")),Oe(t.jsx(q.HiH3,{className:"h-4 w-4"}),"Titulo 3","__h3",()=>Qe("h3"),y.has("formatBlock:h3")),Oe(t.jsx("span",{style:{fontSize:"13px",lineHeight:1},children:"“"}),"Cita","__quote",()=>Qe("blockquote"),y.has("formatBlock:blockquote")),nt(),Oe(t.jsx("b",{children:"B"}),"Negrita (Ctrl+B)","bold"),Oe(t.jsx("i",{children:"I"}),"Cursiva (Ctrl+I)","italic"),Oe(t.jsx("u",{children:"U"}),"Subrayado (Ctrl+U)","underline"),Oe(t.jsx("s",{children:"S"}),"Tachado","strikeThrough"),nt(),Oe(t.jsx(q.HiListBullet,{className:"h-4 w-4"}),"Lista sin orden","insertUnorderedList"),Oe(t.jsx(q.HiNumberedList,{className:"h-4 w-4"}),"Lista numerada","insertOrderedList"),Oe(t.jsx(q.HiArrowTurnUpLeft,{className:"h-4 w-4"}),"Disminuir sangria","outdent"),Oe(t.jsx(q.HiArrowTurnDownRight,{className:"h-4 w-4"}),"Aumentar sangria","indent"),nt(),Oe(t.jsx(q.HiBars3BottomLeft,{className:"h-4 w-4"}),"Alinear izquierda","justifyLeft"),Oe(t.jsx(q.HiBars3CenterLeft,{className:"h-4 w-4"}),"Centrar","justifyCenter"),Oe(t.jsx(q.HiBars3BottomRight,{className:"h-4 w-4"}),"Alinear derecha","justifyRight"),Oe(t.jsx(q.HiBars3,{className:"h-4 w-4"}),"Justificar","justifyFull"),nt(),Oe(t.jsx("span",{style:{fontSize:"10px"},children:"AA"}),"Mayusculas","__upper",()=>Be("uppercase")),Oe(t.jsx("span",{style:{fontSize:"10px"},children:"aa"}),"Minusculas","__lower",()=>Be("lowercase")),Oe(t.jsx("span",{style:{fontSize:"10px"},children:"Aa"}),"Capitalizar","__cap",()=>Be("capitalize")),nt(),Oe(t.jsx(q.HiLink,{className:"h-4 w-4"}),"Insertar enlace (Ctrl+K)","__link",()=>me("link")),Oe(t.jsx(q.HiLinkSlash,{className:"h-4 w-4"}),"Quitar enlace","unlink"),Oe(t.jsx(q.HiPhoto,{className:"h-4 w-4"}),"Insertar imagen","__img",()=>me("image")),Oe(t.jsx(q.HiTableCells,{className:"h-4 w-4"}),"Insertar tabla","__table",()=>me("table")),Oe(t.jsx(q.HiMinus,{className:"h-4 w-4"}),"Insertar separador","__divider",Ot),nt(),Oe(t.jsx(q.HiOutlinePaintBrush,{className:"h-4 w-4"}),"Limpiar formato","removeFormat"),Oe(t.jsx(q.HiNoSymbol,{className:"h-4 w-4"}),"Quitar bloque","__clearBlock",()=>Qe("p")),nt(),t.jsx("button",{type:"button",title:_?"Salir del modo de enfoque (Esc)":"Modo de enfoque",tabIndex:-1,onFocus:rt,onMouseDown:ue=>{ue.preventDefault(),It(_)},className:"flex h-7 w-7 items-center justify-center rounded transition-colors",style:{color:"var(--text-secondary)"},children:_?t.jsx(q.HiArrowsPointingIn,{className:"h-4 w-4"}):t.jsx(q.HiArrowsPointingOut,{className:"h-4 w-4"})})]});return t.jsxs(t.Fragment,{children:[Gt(),t.jsxs("div",{className:"overflow-hidden rounded-lg transition-all duration-150 ring-1 ring-transparent focus-within:ring-primary/30",style:{border:"1px solid var(--border)"},children:[t.jsx("div",{ref:Me,contentEditable:!0,suppressContentEditableWarning:!0,"data-bonsaif-rich-instance":i,onInput:tt,onKeyDown:Ke,onKeyUp:Fe,onSelect:Fe,onMouseUp:Fe,onMouseMove:ge,onMouseLeave:Te,onContextMenu:Le,onMouseDown:Ht,"data-placeholder":n,className:`rich-editor px-3 py-2 text-sm focus:outline-none${C?" is-empty":""}`,style:{color:"var(--text-main)",background:"var(--bg-input)",minHeight:a,maxHeight:"320px",overflowY:"auto",lineHeight:"1.6"}}),pt("var(--bg-input)"),Zt(!1,"var(--bg-input)")]}),t.jsxs(Aa,{open:j,onClose:()=>W(!1),title:"Modo de enfoque",subtitle:"Esc para salir",maxWidth:"920px",bodyClassName:"flex min-h-0 flex-col p-0",panelClassName:"h-[88vh]",backdropClassName:"bg-black/50 backdrop-blur-[2px]",children:[t.jsx("div",{ref:Pe,contentEditable:!0,suppressContentEditableWarning:!0,"data-bonsaif-rich-instance":i,onInput:tt,onKeyDown:Ke,onKeyUp:Fe,onSelect:Fe,onMouseUp:Fe,onMouseMove:ge,onMouseLeave:Te,onContextMenu:Le,onMouseDown:Ht,"data-placeholder":n,className:`rich-editor min-h-0 flex-1 overflow-y-auto px-8 py-6 text-sm focus:outline-none${C?" is-empty":""}`,style:{color:"var(--text-main)",background:"var(--bg-card)",lineHeight:"1.75"}}),pt("var(--bg-input)"),Zt(!0,"var(--bg-input)")]})]})}const Ws="[a-zA-Z0-9._@-]+",Ra=new RegExp(`@(${Ws})`,"g"),vu=/[a-zA-Z0-9._@-]/,tn=new Set([" ",`
26
- `," ","\r"," ","(","[","{",".",",",";",":","!","?","¿","¡",")","]","}",'"',"'","«","»","/","\\","|","-","—","–"]);function js(e,r){if(r<=0)return!0;const n=e[r-1]??"";return tn.has(n)}function qs(e,r,n){var a;if(r<0||r>e.length)return null;for(let s=r-1;s>=0;s-=1){if(e[s]!=="@"){const c=e[s]??"";if(tn.has(c)||!vu.test(c))return null;continue}if((a=n==null?void 0:n.isInsideExistingMention)!=null&&a.call(n,s)||!(n!=null&&n.isTriggerBoundary?n.isTriggerBoundary(s):js(e,s)))continue;const i=e.slice(s+1,r);return i.length>0&&!new RegExp(`^${Ws}$`).test(i)?null:{query:i,triggerIndex:s,caretIndex:r}}return null}function Us(e,r){var a;const n=Cr(e,r);return n?!!((a=n.node.parentElement)!=null&&a.closest(".mention-chip")):!1}function Vs(e,r){if(r<=0)return!0;const n=Cr(e,r);if(!n){const s=ao(e);return js(s,r)}if(n.offset>0){const s=n.node.data[n.offset-1]??"";return tn.has(s)}let a=n.node.previousSibling;for(;a;){if(a.nodeType===Node.TEXT_NODE){const s=a.textContent??"";if(s.length===0){a=a.previousSibling;continue}return tn.has(s[s.length-1]??"")}if(a.nodeType===Node.ELEMENT_NODE){const s=a;if(s.classList.contains("mention-chip")||s.tagName==="BR"||/^(P|DIV|LI|H[1-6]|BLOCKQUOTE)$/i.test(s.tagName))return!0;const l=s.textContent??"";if(l.length===0){a=a.previousSibling;continue}return tn.has(l[l.length-1]??"")}a=a.previousSibling}return!0}function eo(e,r){const n=ao(e);return qs(n,r,{isTriggerBoundary:a=>Vs(e,a),isInsideExistingMention:a=>Us(e,a)})}function to(e){return e.toLowerCase().trim()}function Ys(e){return e?e.replace(/<style[^>]*>[\s\S]*?<\/style>/gi," ").replace(/<script[^>]*>[\s\S]*?<\/script>/gi," ").replace(/<br\s*\/?>/gi,`
23
+ </body></html>`,ke=window.open("","_blank");ke&&(ke.document.write(me),ke.document.close())}const Sa=()=>!Re||!mn?null:ct.createPortal(t.jsxs("div",{ref:So,role:"menu",className:"overflow-hidden rounded-lg border p-1 shadow-xl",style:{...$b,position:"fixed",zIndex:9999,minWidth:170,borderColor:"var(--border)",background:"var(--bg-card)"},children:[t.jsxs("button",{type:"button",role:"menuitem",className:"flex w-full items-center gap-2.5 rounded-md px-2.5 py-1.5 text-sm transition-colors hover:bg-[var(--bg-input)]",style:{color:"var(--text-main)"},onClick:()=>{(async()=>(Ct?await Ct():sm(),ia(!1)))()},children:[t.jsx(q.HiTableCells,{className:"h-4 w-4 shrink-0 text-emerald-500"}),"Descargar CSV / Excel"]}),t.jsxs("button",{type:"button",role:"menuitem",className:"flex w-full items-center gap-2.5 rounded-md px-2.5 py-1.5 text-sm transition-colors hover:bg-[var(--bg-input)]",style:{color:"var(--text-main)"},onClick:()=>{(async()=>(Et?await Et():lm(),ia(!1)))()},children:[t.jsx(q.HiDocumentText,{className:"h-4 w-4 shrink-0 text-red-500"}),"Imprimir / PDF"]})]}),document.body),Ca=()=>{const p=Y&&Ye.trim().length>0,M=ge!=null&&ge.length?ge:p?[{key:"bql",label:"BQL",value:Ye}]:[],R=ie.filter(P=>{const ne=P.trim();return ne?!new Set(Ze.split(`
24
+ `).map(ke=>ke.trim()).filter(Boolean)).has(ne):!1}).slice(0,8);return!ae&&Eo===0&&!Y&&!Re?null:t.jsxs("div",{className:"relative flex min-h-9 flex-wrap items-center justify-between gap-2 border-b rounded-t-lg px-2 py-1",style:{borderColor:"var(--border)",background:"var(--bg-input)"},children:[t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[Eo>0&&t.jsxs("button",{type:"button",onClick:jb,className:"inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium text-[var(--primary)] transition-colors hover:bg-[var(--bg-card)]",children:[t.jsx(q.HiXMark,{className:"h-3.5 w-3.5"}),Eo," filtros"]}),Y&&t.jsxs("div",{ref:No,className:"relative flex min-w-0 flex-1 items-center gap-2",children:[t.jsxs("button",{type:"button",onClick:()=>{if(ot){it(!1);return}ha(),it(!0)},className:"inline-flex h-7 shrink-0 items-center gap-1.5 rounded-md border px-2 text-xs font-bold transition-colors",style:{background:ot?"var(--primary)":p?"color-mix(in srgb, var(--primary) 12%, transparent)":"var(--bg-card)",borderColor:ot||p?"var(--primary)":"var(--border)",color:ot?"var(--primary-fg)":"var(--primary)"},"aria-expanded":ot,title:"Abrir filtros BQL",children:[t.jsx(q.HiCommandLine,{className:"h-3.5 w-3.5"}),"BQL",p&&t.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current"}),ot?t.jsx(q.HiChevronUp,{className:"h-3.5 w-3.5"}):t.jsx(q.HiChevronDown,{className:"h-3.5 w-3.5"})]}),t.jsx("span",{className:"hidden truncate text-xs text-[var(--text-muted)] sm:inline",children:re}),M.length>0&&t.jsxs("div",{className:"hidden min-w-0 items-center gap-1.5 overflow-hidden lg:flex",children:[M.slice(0,3).map(P=>t.jsxs("span",{className:"inline-flex max-w-44 items-center gap-1 truncate rounded-full px-2 py-1 text-xs font-medium",style:{background:"var(--bg-hover)",border:"1px solid var(--primary)",color:"var(--primary)"},children:[t.jsxs("span",{className:"text-[var(--text-muted)]",children:[P.label,":"]}),t.jsx("span",{className:"truncate",children:P.value})]},P.key)),M.length>3&&t.jsxs("span",{className:"text-xs text-[var(--text-muted)]",children:["+",M.length-3]})]}),p&&t.jsx("button",{type:"button","aria-label":"Limpiar BQL",title:"Limpiar BQL",onClick:fi,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-card)] hover:text-[var(--primary)]",children:t.jsx(q.HiXMark,{className:"h-4 w-4"})}),ot&&ct.createPortal(t.jsxs("div",{ref:Rl,className:"flex flex-col gap-3 rounded-lg p-3 shadow-2xl",style:{...Cb,background:"var(--bg-card)",border:"1px solid color-mix(in srgb, var(--primary) 35%, var(--border))"},children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[de.map(P=>t.jsxs("button",{type:"button",onMouseDown:ne=>{ne.preventDefault(),ne.stopPropagation()},onClick:ne=>{ne.preventDefault(),ne.stopPropagation(),pa(P.bql)},className:"inline-flex h-7 items-center gap-1.5 rounded-md border px-2.5 text-xs font-semibold transition-colors hover:border-[var(--primary)] hover:text-[var(--primary)]",style:{background:"var(--bg-input)",borderColor:"var(--border)",color:"var(--text-secondary)"},children:[P.icon,P.label]},P.label)),he.length>0&&t.jsxs("button",{type:"button",onClick:()=>qt(P=>!P),className:"inline-flex h-7 items-center gap-1.5 rounded-md px-2 text-xs font-medium text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-input)] hover:text-[var(--primary)]","aria-expanded":cr,children:[t.jsx(q.HiInformationCircle,{className:"h-3.5 w-3.5"}),"Ejemplos"]}),bn.length>0&&t.jsxs("button",{type:"button",onClick:()=>Hr(P=>!P),className:"inline-flex h-7 items-center gap-1.5 rounded-md px-2 text-xs font-medium text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-input)] hover:text-[var(--primary)]","aria-expanded":fn,children:[t.jsx(q.HiClock,{className:"h-3.5 w-3.5"}),"Historial"]})]}),t.jsxs("div",{className:"overflow-hidden rounded-lg",style:{background:"var(--bg-input)",border:`1.5px solid ${Me?"var(--danger)":p?"var(--primary)":"var(--border)"}`},children:[t.jsx("textarea",{ref:ko,value:Ze,rows:3,onChange:P=>To(P.target.value,P.target),onKeyDown:P=>{P.key==="Enter"&&!P.shiftKey&&(P.preventDefault(),ui(Ze)),P.key==="Escape"&&it(!1)},placeholder:z,autoComplete:"off",spellCheck:!1,className:"block w-full px-4 py-3 text-sm outline-none",style:{background:"var(--bg-input)",color:"var(--text-main)",border:"none",fontFamily:"'SF Mono', 'Fira Code', 'Consolas', monospace",lineHeight:1.6,maxHeight:180,minHeight:88,overflowY:"auto",resize:"vertical"}}),R.length>0&&t.jsx("div",{className:"border-t border-[var(--border)] bg-[var(--bg-card)]",children:R.map(P=>t.jsx("button",{type:"button",onMouseDown:ne=>{ne.preventDefault(),ne.stopPropagation()},onClick:ne=>{ne.preventDefault(),ne.stopPropagation(),pa(P)},className:"block w-full px-4 py-2 text-left text-xs transition-colors hover:bg-[var(--bg-hover)] hover:text-[var(--primary)]",style:{fontFamily:"'SF Mono', 'Fira Code', 'Consolas', monospace"},children:P},P))})]}),t.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[t.jsx("span",{className:"min-w-0 text-xs",style:{color:Me?"var(--danger)":"var(--text-muted)"},children:Me??(p?`${M.length||1} filtro${(M.length||1)===1?"":"s"} activo${(M.length||1)===1?"":"s"}`:"Enter aplica la consulta. Shift + Enter agrega linea.")}),M.map(P=>t.jsxs("span",{className:"inline-flex max-w-56 items-center gap-1 truncate rounded-full px-2 py-1 text-xs font-medium",style:{background:"var(--bg-hover)",border:"1px solid var(--primary)",color:"var(--primary)"},children:[t.jsxs("span",{className:"text-[var(--text-muted)]",children:[P.label,":"]}),t.jsx("span",{className:"truncate",children:P.value})]},P.key))]}),fn&&bn.length>0&&t.jsxs("div",{className:"overflow-hidden rounded-lg border border-[var(--border)] bg-[var(--bg-input)]",children:[t.jsxs("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-3 py-2",children:[t.jsxs("span",{className:"flex items-center gap-1.5 text-xs font-semibold text-[var(--text-secondary)]",children:[t.jsx(q.HiClock,{className:"h-3.5 w-3.5"}),"Historial"]}),t.jsxs("button",{type:"button",onClick:()=>{Br([]),Hr(!1)},className:"inline-flex items-center gap-1 rounded px-2 py-0.5 text-xs text-[var(--text-muted)]",children:[t.jsx(q.HiTrash,{className:"h-3 w-3"}),"Limpiar"]})]}),bn.map(P=>t.jsxs("div",{className:"group flex items-center gap-2 border-b border-[var(--border)] px-3 py-2 last:border-b-0",children:[t.jsx("button",{type:"button",onMouseDown:ne=>{ne.preventDefault(),ne.stopPropagation()},onClick:ne=>{ne.preventDefault(),ne.stopPropagation(),pa(P)},className:"min-w-0 flex-1 text-left",children:t.jsx("code",{className:"block truncate text-xs text-[var(--primary)]",children:P})}),t.jsx("button",{type:"button",onClick:()=>Br(ne=>ne.filter(me=>me!==P)),className:"rounded p-1 text-[var(--text-muted)] opacity-0 transition-opacity group-hover:opacity-100",children:t.jsx(q.HiXMark,{className:"h-3.5 w-3.5"})})]},P))]}),cr&&he.length>0&&t.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:he.map(P=>t.jsxs("button",{type:"button",onMouseDown:ne=>{ne.preventDefault(),ne.stopPropagation()},onClick:ne=>{ne.preventDefault(),ne.stopPropagation(),pa(P.bql),qt(!1)},className:"rounded-lg border border-[var(--border)] bg-[var(--bg-input)] p-2 text-left transition-colors hover:border-[var(--primary)]",children:[t.jsx("code",{className:"block truncate text-xs text-[var(--primary)]",children:P.bql}),P.description&&t.jsx("span",{className:"mt-1 block text-xs text-[var(--text-muted)]",children:P.description})]},P.bql))}),t.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-[var(--border)] pt-3",children:[p&&t.jsxs("button",{type:"button",onClick:fi,className:"inline-flex h-8 items-center gap-1 rounded-md px-2.5 text-xs font-medium text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-input)] hover:text-[var(--primary)]",children:[t.jsx(q.HiXMark,{className:"h-3.5 w-3.5"}),"Limpiar"]}),t.jsxs("button",{type:"button",onClick:()=>ui(Ze),className:"inline-flex h-8 items-center gap-1.5 rounded-md bg-[var(--primary)] px-4 text-xs font-semibold text-[var(--primary-fg)] transition-opacity hover:opacity-90",children:[t.jsx(q.HiCheck,{className:"h-3.5 w-3.5"}),"Aplicar"]})]})]}),document.body)]})]}),Re&&t.jsx("button",{ref:ca,type:"button","aria-haspopup":"menu","aria-expanded":mn,"aria-label":"Exportar datos",title:"Exportar datos",onClick:()=>{var ne;const P=(ne=ca.current)==null?void 0:ne.getBoundingClientRect();P&&Ab({top:P.bottom+4,right:window.innerWidth-P.right}),ia(me=>!me)},className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-card)] hover:text-[var(--primary)] focus:bg-[var(--bg-card)] focus:text-[var(--primary)] ${mn?"bg-[var(--bg-card)] text-[var(--primary)]":""}`,children:t.jsx(q.HiArrowDownTray,{className:"h-4 w-4"})}),ae&&t.jsx("button",{type:"button","aria-haspopup":"menu","aria-expanded":Ke&&Ae==="visibility","aria-label":K,title:K,onClick:P=>mi(P,"visibility"),className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-card)] hover:text-[var(--primary)] focus:bg-[var(--bg-card)] focus:text-[var(--primary)] ${Ke&&Ae==="visibility"?"bg-[var(--bg-card)] text-[var(--primary)]":""}`,children:t.jsx(q.HiCog6Tooth,{className:"h-4 w-4"})})]})},Ti=()=>{if(!tm)return null;const p=Hc(st,Bo);return t.jsxs("div",{"aria-busy":a,className:`grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-center gap-2 rounded-b-xl border-t text-xs select-none ${J?"px-2 py-0.5":"px-3 py-1"}`,style:{borderColor:"var(--border)",background:"var(--bg-input)"},children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{style:{color:"var(--text-muted)"},children:Ut===0?"0 filas":`${rm}–${nm} de ${Ut}`}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("span",{style:{color:"var(--text-muted)"},children:"Filas:"}),t.jsx(ar,{value:String(Ft),onChange:M=>am(Number(M)),options:Lo.map(M=>({value:String(M),label:String(M)})),placeholder:"Filas",searchable:!1,disabled:a,height:X,padding:Z,className:"shrink-0 [&>button]:rounded-md [&>button]:text-xs [&_svg]:h-3.5 [&_svg]:w-3.5",style:{width:W}})]})]}),t.jsxs("div",{className:"flex items-center justify-center gap-0.5",children:[t.jsx("button",{disabled:a||st<=1,onClick:()=>Fo(st-1),onMouseEnter:M=>{M.currentTarget.disabled||(M.currentTarget.style.background="color-mix(in srgb, var(--primary) 14%, var(--bg-card))",M.currentTarget.style.color="var(--primary)")},onMouseLeave:M=>{M.currentTarget.style.background="transparent",M.currentTarget.style.color="var(--text-muted)"},className:"cursor-pointer rounded p-0.5 transition-colors disabled:cursor-not-allowed disabled:opacity-30",style:{background:"transparent",color:"var(--text-muted)"},children:t.jsx(q.HiChevronLeft,{className:"h-3.5 w-3.5"})}),p.map((M,R)=>M==="..."?t.jsx("span",{className:"px-1",style:{color:"var(--text-muted)"},children:"…"},`e${R}`):t.jsx("button",{disabled:a,onClick:()=>Fo(M),onMouseEnter:P=>{P.currentTarget.disabled||M===st||(P.currentTarget.style.background="color-mix(in srgb, var(--primary) 14%, var(--bg-card))",P.currentTarget.style.color="var(--primary)")},onMouseLeave:P=>{P.currentTarget.style.background=M===st?"var(--primary)":"transparent",P.currentTarget.style.color=M===st?"var(--primary-fg)":"var(--text-muted)"},className:"h-5 w-5 cursor-pointer rounded text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-60",style:{background:M===st?"var(--primary)":"transparent",color:M===st?"var(--primary-fg)":"var(--text-muted)"},children:M},M)),t.jsx("button",{disabled:a||st>=Bo,onClick:()=>Fo(st+1),onMouseEnter:M=>{M.currentTarget.disabled||(M.currentTarget.style.background="color-mix(in srgb, var(--primary) 14%, var(--bg-card))",M.currentTarget.style.color="var(--primary)")},onMouseLeave:M=>{M.currentTarget.style.background="transparent",M.currentTarget.style.color="var(--text-muted)"},className:"cursor-pointer rounded p-0.5 transition-colors disabled:cursor-not-allowed disabled:opacity-30",style:{background:"transparent",color:"var(--text-muted)"},children:t.jsx(q.HiChevronRight,{className:"h-3.5 w-3.5"})})]}),t.jsx("div",{"aria-hidden":"true"})]})},im=()=>t.jsxs("div",{className:"w-full min-w-0 max-w-full flex flex-col rounded-lg overflow-hidden",style:{background:"var(--bg-card)",boxShadow:ya},children:[Na(),Sa(),Ca(),t.jsx("div",{ref:Rt,className:"min-w-0 max-w-full overflow-hidden",children:t.jsxs("div",{role:"table",className:"text-sm",style:{width:gn,minWidth:xa},children:[t.jsx("div",{role:"rowgroup",style:y?{position:"sticky",top:0,zIndex:10,backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)"}:void 0,children:wa()}),t.jsx("div",{role:"rowgroup",children:Array.from({length:Math.min(6,s)}).map((p,M)=>t.jsxs("div",{role:"row",className:"grid",style:{gridTemplateColumns:jr,borderBottom:`1px solid ${Oe}`},children:[Tt&&t.jsx("div",{role:"cell",className:`${J?"px-2 py-1.5":"px-3 py-2"} w-10`,style:{borderBottom:`1px solid ${Oe}`,borderRight:`1px solid ${Oe}`}},"select-cell"),wt.map((R,P)=>t.jsx("div",{role:"cell",className:J?"px-2 py-1.5":"px-3 py-2",style:{borderBottom:`1px solid ${Oe}`,borderRight:`1px solid ${Oe}`},children:t.jsx("div",{className:"h-3.5 rounded-full animate-pulse",style:{background:"var(--border)",width:`${ni(M,P)}%`,minWidth:32}})},R.key))]},M))})]})})]}),_o="min-w-0 max-w-full overflow-hidden";return te&&Fe&&!bt?t.jsx(wn,{rows:s,columns:Math.max(4,wt.length||7)}):!a&&r.length===0&&!Co?im():a&&r.length===0?t.jsxs("div",{className:"w-full min-w-0 max-w-full flex flex-col rounded-lg overflow-hidden",style:{background:"var(--bg-card)",boxShadow:ya},children:[Na(),Sa(),Ca(),t.jsx("div",{ref:Rt,className:_o,children:t.jsx(zo.OverlayScrollbarsComponent,{options:{scrollbars:{autoHide:"leave",autoHideDelay:200}},className:"w-full",style:{maxHeight:oi,maxWidth:"100%"},defer:!0,children:t.jsxs("div",{role:"table",className:"text-sm",style:{width:gn,minWidth:xa},children:[t.jsx("div",{role:"rowgroup",style:y?{position:"sticky",top:0,zIndex:10,backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)"}:void 0,children:wa()}),t.jsx("div",{role:"rowgroup",children:Array.from({length:s}).map((p,M)=>t.jsxs("div",{role:"row",className:"grid",style:{gridTemplateColumns:jr,borderBottom:`1px solid ${Oe}`},children:[Tt&&t.jsx("div",{role:"cell",className:`${J?"px-2 py-1.5":"px-3 py-2"} w-10`,style:{borderBottom:`1px solid ${Oe}`,borderRight:`1px solid ${Oe}`}},"select-cell"),wt.map((R,P)=>{const ne=ga[R.key],me=ne!==void 0,ke=R.key===Ho;return t.jsx("div",{role:"cell","data-dt-column-key":R.key,className:J?"px-2 py-1.5":"px-3 py-2",style:me?{position:"sticky",left:ne,zIndex:1,background:"color-mix(in srgb, var(--bg-card) 72%, transparent)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",boxShadow:ke?`3px 0 6px -2px rgba(0,0,0,0.10), inset 0 -1px 0 ${Oe}`:`inset 0 -1px 0 ${Oe}`,borderRight:`1px solid ${Oe}`}:{borderBottom:`1px solid ${Oe}`,borderRight:`1px solid ${Oe}`},children:t.jsx("div",{className:"h-3.5 rounded-full animate-pulse",style:{background:"var(--border)",width:`${ni(M,P)}%`,minWidth:32}})},R.key)})]},M))})]})})}),Ti()]}):!a&&r.length===0?t.jsxs("div",{className:"w-full min-w-0 max-w-full flex flex-col rounded-lg overflow-hidden",style:{background:"var(--bg-card)",boxShadow:ya},children:[Na(),Sa(),Ca(),t.jsx("div",{ref:Rt,className:_o,children:t.jsx("div",{role:"table",className:"text-sm",style:{width:gn,minWidth:xa},children:t.jsx("div",{role:"rowgroup",style:y?{position:"sticky",top:0,zIndex:10,backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)"}:void 0,children:wa()})})}),t.jsxs("div",{className:"flex min-h-[180px] flex-col items-center justify-center gap-3 border-t px-6 py-12 text-center",style:{borderColor:Oe,background:"linear-gradient(180deg, color-mix(in srgb, var(--bg-input) 58%, transparent), var(--bg-card))"},children:[t.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-full border",style:{borderColor:"color-mix(in srgb, var(--primary) 24%, var(--border))",background:"color-mix(in srgb, var(--primary) 8%, var(--bg-card))",color:"var(--primary)"},children:l??t.jsx(q.HiMagnifyingGlass,{className:"h-5 w-5"})}),t.jsx("p",{className:"max-w-sm text-sm font-medium",style:{color:"var(--text-main)"},children:i}),t.jsx("span",{className:"text-xs",style:{color:"var(--text-muted)"},children:"Ajusta la busqueda o cambia los filtros para ver mas informacion."})]})]}):t.jsxs("div",{className:"w-full min-w-0 max-w-full flex flex-col rounded-lg overflow-hidden",style:{background:"var(--bg-card)",boxShadow:ya},children:[Na(),Sa(),Ca(),t.jsx("div",{ref:Rt,className:_o,children:t.jsx(zo.OverlayScrollbarsComponent,{options:{scrollbars:{autoHide:"leave",autoHideDelay:200}},className:"w-full",style:{maxHeight:oi,maxWidth:"100%"},defer:!0,children:t.jsxs("div",{role:"table",className:"text-sm",style:{width:gn,minWidth:xa},children:[t.jsx("div",{role:"rowgroup",style:y?{position:"sticky",top:0,zIndex:10,backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)"}:void 0,children:wa()}),t.jsx("div",{role:"rowgroup",children:yi.map((p,M)=>{const R=n(p),P=Si(x==null?void 0:x(p)),ne=M>0?Si(x==null?void 0:x(yi[M-1])):null,me=P&&P.key!==(ne==null?void 0:ne.key),ke=Tt&&k.has(R),Ce=Tt&&(!$||$(p)),Pe=Wr?(m==null?void 0:m(p))??!0:!1,qe=Pe&&gi.has(R),mt=!!d||v&&Pe,et=ke&&N?"color-mix(in srgb, var(--primary) 8%, var(--bg-card))":M%2===1?"color-mix(in srgb, var(--bg-input) 30%, var(--bg-card))":"var(--bg-card)";return t.jsxs(o.Fragment,{children:[me&&t.jsx("div",{role:"row",className:`grid ${P.className??""}`,style:{gridTemplateColumns:jr},children:t.jsx("div",{role:"cell",className:J?"px-2 py-2":"px-3 py-3",style:{gridColumn:"1 / -1",background:"color-mix(in srgb, var(--primary) 8%, var(--bg-input))",borderBottom:`1px solid ${Oe}`,borderRight:`1px solid ${Oe}`},children:t.jsx("div",{className:"flex min-w-0 items-center justify-between gap-3",children:t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"truncate text-xs font-semibold uppercase tracking-wider text-[var(--text-main)]",children:P.label}),P.description&&t.jsx("div",{className:"mt-0.5 truncate text-xs text-[var(--text-muted)]",children:P.description})]})})})}),t.jsxs("div",{role:"row",onClick:mt?ve=>{const Ee=ve.target;if(!(Ee!=null&&Ee.closest('[data-dt-disable-row-click="true"]'))){if(v&&Pe){xi(R);return}d==null||d(p)}}:void 0,className:`grid transition-colors ${mt?"cursor-pointer":""} ${T?T(p):""}`,style:{gridTemplateColumns:jr,"--dt-row-bg":et,"--dt-sticky-bg":et,background:"var(--dt-row-bg)",borderBottom:`1px solid ${Oe}`},onMouseEnter:ve=>{ke||(ve.currentTarget.style.setProperty("--dt-row-bg","var(--bg-hover)"),ve.currentTarget.style.setProperty("--dt-sticky-bg",om))},onMouseLeave:ve=>{ve.currentTarget.style.setProperty("--dt-row-bg",et),ve.currentTarget.style.setProperty("--dt-sticky-bg",et)},children:[Wr&&t.jsx("div",{role:"cell",className:`${J?"px-2 py-1.5":"px-3 py-2"} flex w-10 items-center justify-center`,style:{borderBottom:`1px solid ${Oe}`,borderRight:`1px solid ${Oe}`},"data-dt-disable-row-click":"true",children:Pe&&t.jsx("button",{type:"button","aria-label":qe?"Contraer fila":"Desplegar fila","aria-expanded":qe,onClick:ve=>{ve.stopPropagation(),xi(R)},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-input)] hover:text-[var(--primary)]",children:qe?t.jsx(q.HiChevronDown,{className:"h-4 w-4"}):t.jsx(q.HiChevronRight,{className:"h-4 w-4"})})}),Tt&&t.jsx("div",{role:"cell",className:`${J?"px-2 py-1.5":"px-3 py-2"} flex w-10 items-center justify-center`,style:Io?{position:"sticky",left:0,zIndex:3,background:"var(--dt-sticky-bg)",boxShadow:`inset 0 -1px 0 ${Oe}`}:{borderBottom:`1px solid ${Oe}`,borderRight:`1px solid ${Oe}`},onClick:ve=>{ve.stopPropagation(),Ce&&h(R)},children:t.jsx(Nn,{size:"sm",checked:ke,disabled:!Ce,"aria-label":Ce?"Seleccionar fila":"Fila no seleccionable",containerClassName:"items-center",className:Ce?"cursor-pointer":"cursor-not-allowed opacity-50",onClick:ve=>ve.stopPropagation(),onChange:()=>{Ce&&h(R)}})}),wt.map(ve=>{const Ee=ga[ve.key],Ne=Ee!==void 0,xe=ve.key===Ho,we=or(ve);return t.jsx("div",{role:"cell","data-dt-column-key":ve.key,"data-dt-disable-row-click":ve.disableRowClick||we?"true":void 0,className:`${we?"px-2 py-1.5 justify-center text-center":`${J?"px-2 py-1.5":"px-3 py-2"} ${wi(ve.align)}`} flex min-w-0 items-center ${$c} ${ve.className??""}`,style:{overflow:"hidden",whiteSpace:"nowrap",...Ne?{position:"sticky",left:Ee,zIndex:3,background:"var(--dt-sticky-bg)",boxShadow:xe?`3px 0 6px -2px rgba(0,0,0,0.10), inset 0 -1px 0 ${Oe}`:`inset 0 -1px 0 ${Oe}`,borderRight:`1px solid ${Oe}`}:{borderBottom:`1px solid ${Oe}`,borderRight:`1px solid ${Oe}`}},children:t.jsx(ls,{children:t.jsx("div",{"data-dt-autofit-content":!0,className:"inline-block max-w-none align-middle",children:ve.cell(p)})})},ve.key)})]}),qe&&u&&t.jsx("div",{role:"row",className:"grid",style:{gridTemplateColumns:jr},children:t.jsx("div",{role:"cell",className:J?"px-2 py-2":"px-3 py-3",style:{gridColumn:"1 / -1",background:"color-mix(in srgb, var(--bg-input) 60%, var(--bg-card))",borderBottom:`1px solid ${Oe}`},children:u(p)})})]},R)})})]})})}),Ti()]})}const Pc={email:{pattern:/^[^\s@]+@[^\s@]+\.[^\s@]+$/,message:"Correo inválido"},integer:{pattern:/^-?\d+$/,message:"Debe ser un número entero"},date:{pattern:/^\d{4}-\d{2}-\d{2}$/,message:"Fecha inválida"}};function _c(e,r){if(r.minLength!==void 0&&e.length<r.minLength)return r.message??`Mínimo ${r.minLength} caracteres`;if(r.maxLength!==void 0&&e.length>r.maxLength)return r.message??`Máximo ${r.maxLength} caracteres`;if(!e)return null;if(r.preset){const n=Pc[r.preset];if(!n.pattern.test(e))return r.message??n.message}return r.pattern&&!r.pattern.test(e)?r.message??"Formato inválido":null}const zc=new Set(["Backspace","Delete","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Tab","Home","End","Enter","Escape"]);function Wc({initialValue:e,type:r,mask:n,onCommit:a,onCancel:s}){const[l,i]=o.useState(e),c=o.useRef(null),d=(n==null?void 0:n.preset)==="date",u=d?"date":r==="number"?"number":"text";return o.useEffect(()=>{var m,b;(m=c.current)==null||m.focus(),d||(b=c.current)==null||b.select()},[d]),t.jsx("input",{ref:c,type:u,value:l,maxLength:n==null?void 0:n.maxLength,onChange:m=>i(m.target.value),onBlur:()=>s(),onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),a(l)),m.key==="Escape"&&(m.preventDefault(),s()),(n==null?void 0:n.preset)==="integer"&&!m.ctrlKey&&!m.metaKey&&!zc.has(m.key)&&!/^[\d-]$/.test(m.key)&&m.preventDefault()},onClick:m=>m.stopPropagation(),className:"w-full min-w-0 border-0 bg-transparent p-0 text-sm text-[var(--text-main)] outline-none"})}function jc({initialValue:e,options:r,loading:n,onCommit:a,onCancel:s}){const l=o.useRef(null);return o.useEffect(()=>{if(n)return;const i=setTimeout(()=>{var c,d;(d=(c=l.current)==null?void 0:c.querySelector("button"))==null||d.click()},0);return()=>clearTimeout(i)},[n]),t.jsx("div",{ref:l,className:"w-full",tabIndex:-1,onKeyDown:i=>{i.key==="Escape"&&(i.stopPropagation(),s())},children:t.jsx(ar,{value:e,onChange:i=>{a(i)},options:r,disabled:n,placeholder:n?"Cargando…":"Seleccionar…",triggerVariant:"ghost",height:30,padding:"0 6px",minOptionsForSearch:1,className:"w-full"})})}const qc={outline:"2px solid var(--primary)",outlineOffset:"-2px",borderRadius:"4px",background:"color-mix(in srgb, var(--primary) 5%, var(--bg-card))"},Pa={outline:"2px solid var(--primary)",outlineOffset:"-2px",borderRadius:"4px"};function Uc({columns:e,data:r,getRowId:n,onCellUpdate:a,readOnly:s=!1,...l}){const[i,c]=o.useState(r),d=o.useRef(null);o.useEffect(()=>{d.current||c(r)},[r]);const[u,m]=o.useState(null);d.current=u;const[b,f]=o.useState(null),g=o.useRef(null);g.current=b;const[v,k]=o.useState({}),[h,A]=o.useState(null),$=o.useRef(null);$.current=h;const[N,T]=o.useState({}),[x,y]=o.useState({}),L=o.useRef(new Set),w=o.useRef(null);o.useEffect(()=>{var _;const C=document.activeElement;(!C||C===document.body)&&((_=w.current)==null||_.focus({preventScroll:!0}))},[]);const W=e.map(C=>{var _,ae,B;return`${C.key}:${((B=(ae=(_=C.editable)==null?void 0:_.select)==null?void 0:ae.options)==null?void 0:B.length)??-1}`}).join("|");o.useEffect(()=>{e.forEach(C=>{var B,I;const _=(I=(B=C.editable)==null?void 0:B.select)==null?void 0:I.options;if(!_)return;const ae=N[C.key];(!L.current.has(C.key)||(ae==null?void 0:ae.length)===0&&_.length>0)&&(L.current.add(C.key),T(E=>({...E,[C.key]:_})))})},[W]);const X=o.useCallback(async(C,_)=>{if(L.current.has(C))return;L.current.add(C);const{url:ae,fetchOptions:B}=_.select??{};if(!(!ae&&!B)){y(I=>({...I,[C]:!0}));try{let I=[];if(B)I=await B();else if(ae){const E=await fetch(ae);if(!E.ok)throw new Error("fetch failed");I=await E.json()}T(E=>({...E,[C]:I}))}catch{T(I=>({...I,[C]:[]}))}finally{y(I=>({...I,[C]:!1}))}}},[]),Z=o.useRef(i);Z.current=i;const D=o.useRef(a);D.current=a;const Q=o.useRef(n);Q.current=n;const j=o.useRef(e);j.current=e;const se=o.useRef(s);se.current=s,o.useEffect(()=>{if(e.length>0&&r.length>0){const C=e.find(_=>_.selectable!==!1);C&&f({rowId:n(r[0]),colKey:C.key})}},[]),o.useEffect(()=>{if(!b)return;const C=w.current;if(!C)return;const _=C.querySelector(`[data-cell-id="${b.rowId}:${b.colKey}"]`);if(!_)return;const ae=C.querySelector('[role="rowgroup"]');_.style.scrollMarginTop=`${(ae==null?void 0:ae.offsetHeight)??0}px`;const B=C.querySelector('[role="row"]');let I=0;B&&B.querySelectorAll('[role="cell"], [role="columnheader"]').forEach(E=>{E.style.position==="sticky"&&E.style.left!==""&&(I=Math.max(I,parseFloat(E.style.left)+E.offsetWidth))}),_.style.scrollMarginLeft=`${I}px`,_.scrollIntoView({block:"nearest",inline:"nearest"})},[b]);const te=o.useCallback(C=>{var I;const _=j.current,ae=new Set,B=[];(I=w.current)==null||I.querySelectorAll("[data-cell-id]").forEach(E=>{const oe=E.dataset.cellId.split(":")[0];ae.has(oe)||(ae.add(oe),B.push(oe))}),f(E=>{if(!E)return E;const oe=_.findIndex(H=>H.key===E.colKey),K=B.indexOf(E.rowId);let Y=oe,S=K;if(C==="up")S=Math.max(0,K-1);else if(C==="down")S=Math.min(B.length-1,K+1);else if(C==="left"){let H=oe-1;for(;H>=0&&_[H].selectable===!1;)H--;H>=0&&(Y=H)}else if(C==="right"){let H=oe+1;for(;H<_.length&&_[H].selectable===!1;)H++;H<_.length&&(Y=H)}return Y===oe&&S===K?E:{rowId:B[S],colKey:_[Y].key}})},[]),ee=o.useCallback((C=!0)=>{const _=d.current;m(null),_&&f(_),C&&setTimeout(()=>{var ae;return(ae=w.current)==null?void 0:ae.focus({preventScroll:!0})},0)},[]),U=o.useCallback(async(C,_,ae)=>{var ie;const B=j.current.find(ge=>ge.key===_);if(!(B!=null&&B.editable))return;const{field:I,type:E,mask:oe,validate:K}=B.editable,Y=E==="number"?ae===""?null:Number(ae):ae;if(oe){const ge=_c(ae,oe);if(ge){k(Me=>({...Me,[`${C}:${_}`]:ge}));return}}if(K){const ge=K(Y);if(ge){k(Me=>({...Me,[`${C}:${_}`]:ge}));return}}const S=Q.current,H=Z.current.find(ge=>S(ge)===C);if(!H)return;const O=H[I];m(null),k(ge=>{const Me={...ge};return delete Me[`${C}:${_}`],Me});const re=Z.current,z=re.findIndex(ge=>S(ge)===C),de=re[Math.min(re.length-1,z+1)];if(f({rowId:S(de),colKey:_}),setTimeout(()=>{var Me,$e;const ge=document.activeElement;(!ge||ge===document.body||(Me=w.current)!=null&&Me.contains(ge))&&(($e=w.current)==null||$e.focus({preventScroll:!0}))},0),String(O??"")===String(Y??""))return;const he={...H,[I]:Y};c(ge=>ge.map(Me=>S(Me)===C?he:Me)),A({rowId:C,colKey:_});try{await((ie=D.current)==null?void 0:ie.call(D,{row:H,rowId:C,field:I,oldValue:O,newValue:Y}))}catch{c(ge=>ge.map(Me=>S(Me)===C?H:Me)),k(ge=>({...ge,[`${C}:${_}`]:"Error al guardar. Intenta de nuevo."}))}finally{A(null)}},[]),J=o.useCallback(C=>{if($.current){C.preventDefault();return}if(d.current)return;const _=g.current;if(!(!_||!["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Enter","Escape","Tab"].includes(C.key)))switch(C.preventDefault(),C.key){case"ArrowUp":te("up");break;case"ArrowDown":te("down");break;case"ArrowLeft":te("left");break;case"ArrowRight":te("right");break;case"Tab":te(C.shiftKey?"left":"right");break;case"Enter":{const B=j.current.find(I=>I.key===_.colKey);B!=null&&B.editable&&!se.current?(m(_),B.editable.type==="select"&&!L.current.has(_.colKey)&&X(_.colKey,B.editable)):te("down");break}}},[te,X]),ce=o.useMemo(()=>e.map(C=>{if(!C.editable||s){const ae={...C};if(delete ae.editable,delete ae.selectable,C.selectable===!1)return{...ae,disableRowClick:!0};const B=ae.cell;return{...ae,className:`relative ${ae.className??""}`.trim(),disableRowClick:!0,cell:I=>{const E=n(I),oe=(b==null?void 0:b.rowId)===E&&(b==null?void 0:b.colKey)===C.key;return t.jsxs(t.Fragment,{children:[t.jsx("span",{"data-cell-id":`${E}:${C.key}`,className:"absolute inset-0 z-10 cursor-default",onClick:()=>{var K;$.current||(f({rowId:E,colKey:C.key}),(K=w.current)==null||K.focus({preventScroll:!0}))}}),oe&&t.jsx("div",{className:"pointer-events-none absolute inset-0 z-20",style:Pa}),t.jsx("span",{className:"relative z-0 pointer-events-none",children:B(I)})]})}}}const _=C.editable;return{...C,className:`relative ${C.className??""}`.trim(),disableRowClick:!0,cell:ae=>{const B=n(ae),I=C.key,E=(u==null?void 0:u.rowId)===B&&(u==null?void 0:u.colKey)===I,oe=(b==null?void 0:b.rowId)===B&&(b==null?void 0:b.colKey)===I,K=v[`${B}:${I}`],Y=(h==null?void 0:h.rowId)===B&&(h==null?void 0:h.colKey)===I,S=ae[_.field],H=String(S??""),O=()=>{var z;$.current||(f({rowId:B,colKey:I}),m({rowId:B,colKey:I}),(z=w.current)==null||z.focus({preventScroll:!0}),_.type==="select"&&!L.current.has(I)&&X(I,_))};if(E){const z=_.type==="select"?t.jsx(jc,{initialValue:H,options:N[I]??[],loading:x[I]??!1,onCommit:de=>U(B,I,de),onCancel:ee}):t.jsx(Wc,{initialValue:H,type:_.type??"text",mask:_.mask,onCommit:de=>U(B,I,de),onCancel:ee});return t.jsx("div",{className:"absolute inset-0 flex items-center px-2",style:qc,onClick:de=>de.stopPropagation(),children:z})}const re=C.cell(ae);return t.jsxs(t.Fragment,{children:[t.jsx("span",{"data-cell-id":`${B}:${I}`,className:`peer absolute inset-0 z-10 ${Y?"cursor-wait":"cursor-pointer"}`,onClick:O}),oe&&!Y&&t.jsx("div",{className:"pointer-events-none absolute inset-0 z-20",style:Pa}),Y&&t.jsxs("div",{className:"pointer-events-none absolute inset-0 z-20 flex items-center gap-1.5 bg-[var(--bg-card)]/80 px-2",style:Pa,children:[t.jsx("span",{className:"h-3 w-3 shrink-0 animate-spin rounded-full border-2 border-[var(--text-muted)] border-t-transparent","aria-hidden":!0}),t.jsx("span",{className:"truncate text-xs text-[var(--text-muted)]",children:"Guardando…"})]}),t.jsx("span",{className:"relative z-0 inline-flex items-center gap-1 pointer-events-none",children:K?t.jsxs("span",{className:"flex items-center gap-1 text-red-500",children:[t.jsx(q.HiExclamationCircle,{className:"h-3.5 w-3.5 shrink-0"}),t.jsx("span",{className:"truncate text-xs",children:K})]}):t.jsx("span",{className:"truncate",children:re})}),!Y&&t.jsx(q.HiPencil,{className:"pointer-events-none absolute right-1 top-1/2 z-0 h-3 w-3 -translate-y-1/2 shrink-0 text-[var(--text-muted)] opacity-0 transition-opacity peer-hover:opacity-40"})]})}}}),[e,s,u,b,h,v,N,x,n,U,ee,X]);return t.jsx("div",{ref:w,tabIndex:0,onKeyDown:J,onBlur:C=>{var _;(_=w.current)!=null&&_.contains(C.relatedTarget)||setTimeout(()=>{var B,I;const ae=document.activeElement;ae&&((B=ae.closest)!=null&&B.call(ae,"[data-bonsaif-select-dropdown]"))||(I=w.current)!=null&&I.contains(ae)||ee(!1)},0)},style:{width:"100%",minWidth:0,outline:"none"},children:t.jsx(is,{...l,columns:ce,data:i,getRowId:n})})}function nt(e){if(e)return new Date(`${e}T12:00:00`)}function kt(e){const r=e.getFullYear(),n=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return`${r}-${n}-${a}`}function yr(e){return e.charAt(0).toUpperCase()+e.slice(1)}function cs(e){return e.map(r=>nt(r)).filter(r=>!!r)}function Vc(e){if(!(e!=null&&e.length))return[];const r=new Set(e.map(kt));return Array.from(r).sort()}function _a(e){return new Intl.DateTimeFormat("es-MX",{weekday:"short"}).format(e)}function ds(e){const r=nt(e);if(!r)return e;const n=_a(r).replace(/\.$/u,"").replace(/^\w/u,s=>s.toUpperCase()),a=new Intl.DateTimeFormat("es-MX",{month:"short"}).format(r).replace(/\.$/u,"").toLowerCase();return`${n} - ${r.getDate()} ${a} ${r.getFullYear()}`}const za={weekend:{dayOfWeek:[0,6]}},Wa={weekend:"bonsaif-weekend"};function ja({children:e,className:r="",...n}){const a=String(e??"").toLowerCase().normalize("NFD").replace(new RegExp("\\p{M}","gu"),"").trim(),s=a.startsWith("sab")||a.startsWith("dom")||a==="s"||a==="d";return t.jsx("th",{...n,className:`${r} ${s?"bonsaif-weekday-weekend":""}`.trim(),children:e})}const Yc={background:"var(--primary)",color:"var(--primary-fg, #ffffff)",borderRadius:999},Xc={background:"color-mix(in srgb, var(--primary) 22%, transparent)",color:"var(--text-main)",borderRadius:999};function Kc({day:e,modifiers:r,...n}){const a=r.range_start||r.range_end||r.selected&&!r.range_middle,s=!!r.range_middle,l=!!r.weekend||e.date.getDay()===0||e.date.getDay()===6;return t.jsx("button",{...n,type:"button",className:`bonsaif-multi-day-btn${a?" is-range-edge":""}${s?" is-range-middle":""}${l?" bonsaif-day-weekend":""} ${n.className??""}`,style:{...a?Yc:null,...s?Xc:null,...l?{fontWeight:800}:null,...n.style}})}function Gc({startDate:e,endDate:r,onChange:n,minDate:a,viewMonth:s,numberOfMonths:l=1,orientation:i="horizontal",showSummary:c=!0,startLabel:d="Inicio",endLabel:u="Regreso",className:m=""}){const b={from:nt(e),to:nt(r)},f=nt(a),[g,v]=o.useState(()=>nt(s||e)??new Date);o.useEffect(()=>{const N=nt(s||e);N&&v(N)},[s,e]);const k=o.useMemo(()=>{if(l<=1)return yr(new Intl.DateTimeFormat("es-MX",{month:"long",year:"numeric"}).format(g));const N=new Date(g.getFullYear(),g.getMonth()+l-1,1),T=g.getFullYear()===N.getFullYear(),x=new Intl.DateTimeFormat("es-MX",{month:"short",...T?{}:{year:"numeric"}}).format(g),y=new Intl.DateTimeFormat("es-MX",{month:"short",year:"numeric"}).format(N);return`${yr(x)} – ${yr(y)}`},[g,l]);function h(){v(new Date(g.getFullYear(),g.getMonth()-1,1))}function A(){v(new Date(g.getFullYear(),g.getMonth()+1,1))}const $=l>1?`bonsaif-range-months bonsaif-range-months--multi bonsaif-range-months--${i}`:"bonsaif-range-months";return t.jsxs("div",{className:`bonsaif-calendar bonsaif-date-range-picker ${m}`.trim(),children:[t.jsxs("div",{className:"bonsaif-cal-shell",children:[t.jsxs("div",{className:"bonsaif-cal-toolbar",children:[t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn","aria-label":"Mes anterior",onClick:h,children:t.jsx(q.HiChevronLeft,{size:16})}),t.jsx("span",{className:"bonsaif-cal-title",children:k}),t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn","aria-label":"Mes siguiente",onClick:A,children:t.jsx(q.HiChevronRight,{size:16})})]}),t.jsx(Ta.DayPicker,{mode:"range",selected:b,month:g,onMonthChange:v,onSelect:N=>{const T=N!=null&&N.from?kt(N.from):e,x=N!=null&&N.to?kt(N.to):"";n({startDate:T,endDate:x})},numberOfMonths:l,hideNavigation:!0,weekStartsOn:1,disabled:f?{before:f}:void 0,showOutsideDays:!1,modifiers:za,modifiersClassNames:Wa,components:{DayButton:Kc,Weekday:ja},classNames:{root:"bonsaif-range-daypicker w-full",months:$,month:l>1?"bonsaif-multi-month bonsaif-range-month-card":"bonsaif-multi-month",month_caption:l>1?"bonsaif-range-month-caption":"bonsaif-multi-caption-hidden",month_grid:"bonsaif-multi-month-grid",weekdays:"bonsaif-multi-weekdays",weekday:"bonsaif-multi-weekday",week:"bonsaif-multi-week",day:"bonsaif-multi-day",day_button:"bonsaif-multi-day-btn",selected:"bonsaif-range-day-selected",range_start:"bonsaif-range-start",range_middle:"bonsaif-range-middle",range_end:"bonsaif-range-end",today:"bonsaif-multi-day-today",disabled:"bonsaif-multi-day-disabled",hidden:"bonsaif-multi-day-hidden"},formatters:{formatCaption:N=>`${yr(new Intl.DateTimeFormat("es-MX",{month:"long"}).format(N))} ${N.getFullYear()}`,formatWeekdayName:_a}})]}),c?t.jsx("div",{className:"bonsaif-cal-summary",children:e?t.jsxs("div",{className:"bonsaif-cal-chips",children:[t.jsxs("span",{className:"bonsaif-cal-chip bonsaif-cal-chip--static",children:[d,": ",e]}),r?t.jsxs("span",{className:"bonsaif-cal-chip bonsaif-cal-chip--static",children:[u,": ",r]}):null]}):t.jsx("span",{children:"Sin rango seleccionado"})}):null]})}function us({day:e,modifiers:r,onDayPointerDown:n,onDayPointerEnter:a,onDayClickSelect:s,...l}){const i=!!(r.disabled||r.hidden),c=!!r.weekend||e.date.getDay()===0||e.date.getDay()===6;return t.jsx("button",{...l,type:"button",disabled:i||l.disabled,className:`${l.className??""}${c?" bonsaif-day-weekend":""}`,style:{...c?{fontWeight:800}:null,...l.style},onPointerDown:d=>{var u;i||(n==null||n(e.date,d),(u=l.onPointerDown)==null||u.call(l,d))},onPointerEnter:()=>{i||a==null||a(e.date)},onClick:d=>{i||(d.preventDefault(),d.stopPropagation(),s==null||s(e.date,d))}})}function fs(e,r){const n=nt(e),a=nt(r);if(!n||!a)return[];const s=n<=a?n:a,l=n<=a?a:n,i=[],c=new Date(s);for(;c<=l;)i.push(kt(c)),c.setDate(c.getDate()+1);return i}function bs(e,r=1){const n=e.getDay(),a=r===1?(n+6)%7:n,s=new Date(e);return s.setHours(12,0,0,0),s.setDate(s.getDate()-a),Array.from({length:7},(l,i)=>{const c=new Date(s);return c.setDate(s.getDate()+i),c})}function Rr(e,r,n){const a=new Set(e);for(const s of r)n==="add"?a.add(s):n==="remove"||a.has(s)?a.delete(s):a.add(s);return Array.from(a).sort()}function Zc(e,r){return typeof r!="number"||r<=0||e.length<=r?e:e.slice(-r)}function Qc(e,r,n){return!!(r&&e<r||n&&e>n)}function ms({value:e,onChange:r,disabled:n=!1,minDate:a,maxDate:s,maxDates:l,isDateDisabled:i,retainOutsidePrefix:c}){const d=o.useRef(null),u=o.useRef(null),m=o.useRef(!1),b=o.useRef(e);b.current=e;const f=o.useCallback(x=>{let y=x;if(c){const L=b.current.filter(W=>!W.startsWith(c)),w=x.filter(W=>W.startsWith(c));y=[...L,...w].sort()}r==null||r(Zc(y,l))},[l,r,c]),g=o.useCallback((x,y=!1)=>Qc(x,a,s)?!0:!(!(i!=null&&i(x))||y&&b.current.includes(x)),[i,s,a]),v=o.useCallback(x=>x.filter(y=>!g(y)),[g]),k=o.useCallback(()=>{u.current=null},[]);o.useEffect(()=>{const x=()=>k();return window.addEventListener("pointerup",x),window.addEventListener("pointercancel",x),()=>{window.removeEventListener("pointerup",x),window.removeEventListener("pointercancel",x)}},[k]);const h=o.useCallback((x,y,L,w)=>{const W=v(fs(x,y));f(L==="add"?Rr(w,W,"add"):Rr(w,W,"remove"))},[f,v]),A=o.useCallback((x,y)=>{if(n||y.button!==0)return;const L=kt(x);if(g(L,!0)||y.shiftKey)return;m.current=!0;const w=[...b.current],W=w.includes(L)?"remove":"add";W==="add"&&g(L)||(u.current={active:!0,mode:W,anchor:L,latest:L,baseline:w},d.current=L,h(L,L,W,w),y.preventDefault())},[h,n,g]),$=o.useCallback(x=>{const y=u.current;if(!(y!=null&&y.active)||n)return;const L=kt(x);y.mode==="add"&&g(L)||y.latest!==L&&(y.latest=L,h(y.anchor,L,y.mode,y.baseline))},[h,n,g]),N=o.useCallback((x,y)=>{if(n)return;const L=kt(x);if(!g(L,!0)){if(m.current&&!y.shiftKey){m.current=!1,y.preventDefault(),y.stopPropagation();return}if(m.current=!1,y.shiftKey&&d.current){y.preventDefault(),y.stopPropagation();const w=v(fs(d.current,L));f(Rr(b.current,w,"add"));return}!b.current.includes(L)&&g(L)||(d.current=L,f(Rr(b.current,[L],"toggle")))}},[f,n,v,g]),T=o.useCallback(x=>{if(n)return;const y=v(Vc(x));if(!y.length)return;const L=y.every(w=>b.current.includes(w));f(Rr(b.current,y,L?"remove":"add")),d.current=y[0]??d.current},[f,n,v]);return{onDayPointerDown:A,onDayPointerEnter:$,onDayClick:N,toggleWeek:T,endDrag:k}}function en(e){return bs(e,1)[0]}function ps(e,r){const n=new Date(e);return n.setDate(n.getDate()+r),n}function Jc({value:e=[],onChange:r,minDate:n,maxDate:a,isDateDisabled:s,viewMonth:l,maxDates:i,showWeekNumbers:c=!1,viewMode:d,defaultViewMode:u="month",onViewModeChange:m,showSummary:b=!0,className:f="",disabled:g=!1}){const v=o.useMemo(()=>cs(e),[e]),k=o.useMemo(()=>new Set(e),[e]),h=nt(n),A=nt(a),[$,N]=o.useState(()=>nt(l||e[0])??new Date),[T,x]=o.useState(()=>en(nt(l||e[0])??new Date)),[y,L]=o.useState(u),w=d??y;function W(C){d===void 0&&L(C),m==null||m(C)}o.useEffect(()=>{const C=nt(l);C&&(N(C),x(en(C)))},[l]);const{onDayPointerDown:X,onDayPointerEnter:Z,onDayClick:D,toggleWeek:Q}=ms({value:e,onChange:r,disabled:g,minDate:n,maxDate:a,maxDates:i,isDateDisabled:s}),j=o.useMemo(()=>{if(g)return!0;const C=[];return h&&C.push({before:h}),A&&C.push({after:A}),s&&C.push(_=>s(kt(_))),C.length>0?C:void 0},[g,s,A,h]),se=o.useCallback(C=>t.jsx(us,{...C,className:`bonsaif-multi-day-btn ${C.className??""}`,onDayPointerDown:X,onDayPointerEnter:Z,onDayClickSelect:D}),[D,X,Z]),te=o.useMemo(()=>bs(T,1),[T]),ee=te[6],U=w==="week"?`${new Intl.DateTimeFormat("es-MX",{day:"numeric",month:"short"}).format(te[0])} – ${new Intl.DateTimeFormat("es-MX",{day:"numeric",month:"short",year:"numeric"}).format(ee)}`:yr(new Intl.DateTimeFormat("es-MX",{month:"long",year:"numeric"}).format($));function J(){if(w==="week"){const C=ps(T,-7);x(en(C)),N(C);return}N(new Date($.getFullYear(),$.getMonth()-1,1))}function ce(){if(w==="week"){const C=ps(T,7);x(en(C)),N(C);return}N(new Date($.getFullYear(),$.getMonth()+1,1))}return t.jsxs("div",{className:`bonsaif-calendar bonsaif-multi-date-calendar ${f}`,children:[t.jsxs("div",{className:"bonsaif-cal-shell",children:[t.jsxs("div",{className:"bonsaif-cal-view-toggle",role:"tablist","aria-label":"Vista",children:[t.jsx("button",{type:"button",role:"tab","aria-selected":w==="month",className:`bonsaif-cal-view-btn${w==="month"?" is-active":""}`,disabled:g,onClick:()=>{W("month"),N(T)},children:"Mes"}),t.jsx("button",{type:"button",role:"tab","aria-selected":w==="week",className:`bonsaif-cal-view-btn${w==="week"?" is-active":""}`,disabled:g,onClick:()=>{W("week"),x(en($))},children:"Semana"})]}),t.jsxs("div",{className:"bonsaif-cal-toolbar",children:[t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn","aria-label":w==="week"?"Semana anterior":"Mes anterior",disabled:g,onClick:J,children:t.jsx(q.HiChevronLeft,{size:16})}),t.jsx("span",{className:"bonsaif-cal-title",children:U}),t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn","aria-label":w==="week"?"Semana siguiente":"Mes siguiente",disabled:g,onClick:ce,children:t.jsx(q.HiChevronRight,{size:16})})]}),t.jsxs("p",{className:"bonsaif-cal-hint",children:["Click · Shift+click rango · Arrastra",c&&w==="month"?" · Semana (nº)":"",w==="week"?" · Botón semana completa":""]}),w==="month"?t.jsx(Ta.DayPicker,{mode:"multiple",required:!1,selected:v,month:$,onMonthChange:N,onSelect:()=>{},hideNavigation:!0,showOutsideDays:!1,weekStartsOn:1,showWeekNumber:c,onWeekNumberClick:(C,_)=>{Q(_)},disabled:j,className:"bonsaif-multi-daypicker",modifiers:za,modifiersClassNames:Wa,classNames:{root:"bonsaif-multi-daypicker",months:"bonsaif-multi-months",month:"bonsaif-multi-month",month_caption:"bonsaif-multi-caption-hidden",month_grid:"bonsaif-multi-month-grid",weekdays:c?"bonsaif-multi-weekdays bonsaif-multi-weekdays--with-week":"bonsaif-multi-weekdays",weekday:"bonsaif-multi-weekday",week:c?"bonsaif-multi-week bonsaif-multi-week--with-week":"bonsaif-multi-week",week_number:"bonsaif-week-number",week_number_header:"bonsaif-week-number-header",day:"bonsaif-multi-day",day_button:"bonsaif-multi-day-btn",selected:"bonsaif-multi-day-selected",today:"bonsaif-multi-day-today",disabled:"bonsaif-multi-day-disabled",hidden:"bonsaif-multi-day-hidden"},components:{DayButton:se,Weekday:ja},formatters:{formatWeekdayName:_a}}):t.jsxs("div",{className:"bonsaif-week-view",children:[t.jsx("div",{className:"bonsaif-week-view-head",children:te.map(C=>t.jsx("div",{className:"bonsaif-multi-weekday",children:new Intl.DateTimeFormat("es-MX",{weekday:"short"}).format(C)},`h-${kt(C)}`))}),t.jsx("div",{className:"bonsaif-week-view-days",children:te.map(C=>{const _=kt(C),ae=k.has(_),B=g||(n?_<n:!1)||(a?_>a:!1)||!!(s!=null&&s(_)),I=_===kt(new Date);return t.jsx("div",{className:`bonsaif-multi-day${ae?" bonsaif-multi-day-selected":""}${I?" bonsaif-multi-day-today":""}${B?" bonsaif-multi-day-disabled":""}`,children:t.jsxs("button",{type:"button",className:"bonsaif-multi-day-btn",disabled:B,"aria-pressed":ae,onPointerDown:E=>X(C,E),onPointerEnter:()=>Z(C),onClick:E=>D(C,E),children:[t.jsx("span",{className:"bonsaif-week-day-num",children:C.getDate()}),t.jsx("span",{className:"bonsaif-week-day-month",children:new Intl.DateTimeFormat("es-MX",{month:"short"}).format(C)})]})},_)})}),t.jsx("button",{type:"button",className:"bonsaif-week-select-all",disabled:g,onClick:()=>Q(te),children:"Marcar / desmarcar semana"})]})]}),b?t.jsx("div",{className:"bonsaif-cal-summary",children:e.length===0?t.jsx("span",{children:"Sin fechas seleccionadas"}):t.jsxs(t.Fragment,{children:[t.jsxs("span",{children:[e.length," ",e.length===1?"fecha":"fechas"]}),t.jsx("div",{className:"bonsaif-cal-chips",children:e.map(C=>t.jsxs("button",{type:"button",className:"bonsaif-cal-chip",disabled:g,onClick:()=>r==null?void 0:r(e.filter(_=>_!==C)),title:`Quitar ${C}`,children:[ds(C),t.jsx("span",{"aria-hidden":!0,children:"×"})]},C))})]})}):null]})}const Rc=Array.from({length:12},(e,r)=>r);function ed({value:e=[],onChange:r,year:n,onYearChange:a,minDate:s,maxDate:l,maxDates:i,showSummary:c=!0,className:d="",disabled:u=!1,readOnly:m=!1}){const b=o.useMemo(()=>cs(e),[e]),f=nt(s),g=nt(l),v=n??(e[0]?Number(e[0].slice(0,4)):new Date().getFullYear()),[k,h]=o.useState(v);o.useEffect(()=>{typeof n=="number"&&h(n)},[n]);function A(w){h(w),a==null||a(w)}const{onDayPointerDown:$,onDayPointerEnter:N,onDayClick:T}=ms({value:e,onChange:r,disabled:u||m,minDate:s,maxDate:l,maxDates:i,retainOutsidePrefix:`${k}-`}),x=o.useCallback(w=>t.jsx(us,{...w,className:`bonsaif-year-day-btn ${w.className??""}`,onDayPointerDown:$,onDayPointerEnter:N,onDayClickSelect:T}),[T,$,N]),y=b.filter(w=>w.getFullYear()===k),L=u?!0:[...f?[{before:f}]:[],...g?[{after:g}]:[]];return t.jsxs("div",{className:`bonsaif-calendar bonsaif-year-multi-date-calendar${m?" bonsaif-year-multi-date-calendar--readonly":""} ${d}`,children:[t.jsxs("div",{className:"bonsaif-cal-shell bonsaif-year-cal-shell",children:[t.jsxs("div",{className:"bonsaif-cal-toolbar",children:[t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn","aria-label":"Año anterior",disabled:u,onClick:()=>A(k-1),children:t.jsx(q.HiChevronLeft,{size:16})}),t.jsx("span",{className:"bonsaif-cal-title",children:k}),t.jsx("button",{type:"button",className:"bonsaif-cal-nav-btn","aria-label":"Año siguiente",disabled:u,onClick:()=>A(k+1),children:t.jsx(q.HiChevronRight,{size:16})})]}),!m&&!u?t.jsx("p",{className:"bonsaif-cal-hint",children:"Click · Shift+click rango · Arrastra para marcar varias"}):null,t.jsx("div",{className:"bonsaif-year-cal-grid",children:Rc.map(w=>{const W=new Date(k,w,1);return t.jsxs("div",{className:"bonsaif-year-cal-month",children:[t.jsx("div",{className:"bonsaif-year-cal-month-title",children:yr(new Intl.DateTimeFormat("es-MX",{month:"long"}).format(W))}),t.jsx(Ta.DayPicker,{mode:"multiple",required:!1,selected:y,month:W,onMonthChange:()=>{},onSelect:()=>{},numberOfMonths:1,hideNavigation:!0,showOutsideDays:!1,weekStartsOn:1,disabled:L,className:"bonsaif-year-month-picker",modifiers:za,modifiersClassNames:Wa,classNames:{root:"bonsaif-year-month-picker",months:"bonsaif-year-month-months",month:"bonsaif-year-month-inner",month_caption:"bonsaif-year-month-caption-hidden",month_grid:"bonsaif-year-month-grid",weekdays:"bonsaif-year-weekdays",weekday:"bonsaif-year-weekday",week:"bonsaif-year-week",day:"bonsaif-year-day",day_button:"bonsaif-year-day-btn",selected:"bonsaif-year-day-selected",today:"bonsaif-year-day-today",disabled:"bonsaif-year-day-disabled",hidden:"bonsaif-year-day-hidden"},components:{DayButton:x,Weekday:ja},formatters:{formatWeekdayName:X=>new Intl.DateTimeFormat("es-MX",{weekday:"narrow"}).format(X)}})]},`${k}-${w}`)})})]}),c?t.jsx("div",{className:"bonsaif-cal-summary",children:e.length===0?t.jsx("span",{children:"Sin fechas seleccionadas"}):t.jsxs(t.Fragment,{children:[t.jsxs("span",{children:[e.length," ",e.length===1?"fecha":"fechas"," ·"," ",k]}),t.jsx("div",{className:"bonsaif-cal-chips",children:e.map(w=>t.jsxs("button",{type:"button",className:"bonsaif-cal-chip",disabled:u||m,onClick:()=>r==null?void 0:r(e.filter(W=>W!==w)),title:`Quitar ${w}`,children:[ds(w),t.jsx("span",{"aria-hidden":!0,children:"×"})]},w))})]})}):null]})}const td="bonsaif-ui:hide-tooltips";function hs(){window.dispatchEvent(new CustomEvent(td))}function rd(e){if(e!==void 0)return typeof e=="number"?`${e}px`:e}function nd({trigger:e,items:r,align:n="end",width:a=220,disabled:s=!1,className:l="",menuClassName:i="",onOpenChange:c}){const[d,u]=o.useState(!1),[m,b]=o.useState(!1),[f,g]=o.useState({}),v=o.useRef(null),k=o.useRef(null),h=o.useCallback(x=>{u(x),c==null||c(x)},[c]),A=o.useCallback(()=>{const x=v.current;if(!x)return;const y=x.getBoundingClientRect(),L=typeof a=="number"?a:y.width,w=typeof a=="number"?a:Math.max(y.width,180),W=n==="end"?Math.max(8,y.right-w):Math.min(y.left,window.innerWidth-w-8),X=window.innerHeight-y.bottom,Z=X<240&&y.top>X?void 0:y.bottom+6,D=Z===void 0?window.innerHeight-y.top+6:void 0;g({position:"fixed",zIndex:9999,left:W,top:Z,bottom:D,width:rd(typeof a=="number"?L:a)})},[n,a]);o.useEffect(()=>b(!0),[]),o.useEffect(()=>{if(!d)return;A();const x=L=>{var W,X;const w=L.target;!((W=v.current)!=null&&W.contains(w))&&!((X=k.current)!=null&&X.contains(w))&&h(!1)},y=L=>{L.key==="Escape"&&h(!1)};return document.addEventListener("mousedown",x),window.addEventListener("keydown",y),window.addEventListener("resize",A),window.addEventListener("scroll",A,!0),()=>{document.removeEventListener("mousedown",x),window.removeEventListener("keydown",y),window.removeEventListener("resize",A),window.removeEventListener("scroll",A,!0)}},[d,h,A]);const $=x=>{s||(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),h(!d))},N=o.isValidElement(e)?o.cloneElement(e,{onClick:()=>{s||(hs(),h(!d))}}):e,T=d?t.jsx("div",{ref:k,role:"menu","data-bonsaif-overlay":"true",className:`overflow-hidden rounded-lg border border-[var(--border)] bg-[var(--bg-card)] p-1 shadow-xl ${i}`,style:f,children:r.map(x=>t.jsxs("div",{children:[x.separatorBefore&&t.jsx("div",{className:"my-1 border-t border-[var(--border)]"}),t.jsxs("button",{type:"button",role:"menuitem",disabled:x.disabled,onClick:()=>{var y;x.disabled||(hs(),(y=x.onSelect)==null||y.call(x),h(!1))},className:"flex w-full min-w-0 items-start gap-2 rounded-md px-2.5 py-1.5 text-left transition-colors hover:bg-[var(--bg-input)] disabled:cursor-not-allowed disabled:opacity-50",style:{color:x.danger?"var(--danger)":"var(--text-main)"},children:[x.icon&&t.jsx("span",{className:"mt-0.5 shrink-0",children:x.icon}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate text-sm font-medium",children:x.label}),x.description&&t.jsx("span",{className:"block truncate text-xs text-[var(--text-muted)]",children:x.description})]})]})]},x.id))}):null;return t.jsxs("span",{ref:v,role:"button",tabIndex:s?-1:0,"aria-haspopup":"menu","aria-expanded":d,onKeyDown:$,className:`inline-flex ${s?"pointer-events-none opacity-60":""} ${l}`,children:[N,m&&T?ct.createPortal(T,document.body):null]})}const ad=180,gs="bg-[color-mix(in_srgb,var(--bg-main)_72%,transparent)] backdrop-blur-sm";function od({open:e,onClose:r,title:n,subtitle:a,leadingIcon:s,confirmLabel:l="Guardar",onConfirm:i,loading:c=!1,confirmDisabled:d=!1,headerActions:u,bodyClassName:m="flex-1 overflow-y-auto px-6 py-5",width:b=440,hasUnsavedChanges:f=!1,unsavedChangesTitle:g="Descartar cambios",unsavedChangesDescription:v="Hay cambios sin guardar. Si cierras el drawer se perderán.",unsavedChangesConfirmLabel:k="Descartar",unsavedChangesCancelLabel:h="Seguir editando",onDiscardChanges:A,disabled:$=!1,disabledMessage:N,children:T}){const[x,y]=o.useState(!1),[L,w]=o.useState(!1),[W,X]=o.useState(!1),Z=o.useCallback(()=>{w(!0),requestAnimationFrame(()=>{requestAnimationFrame(()=>X(!0))})},[]),D=o.useCallback(()=>{X(!1),window.setTimeout(()=>w(!1),ad)},[]),Q=$||c,j=o.useCallback(()=>{if(!Q){if(f){Z();return}r()}},[Q,f,r,Z]),se=o.useCallback(()=>{X(!1),w(!1),A==null||A(),r()},[r,A]);if(o.useEffect(()=>{y(!0)},[]),o.useEffect(()=>(document.body.style.overflow=e?"hidden":"",e||(X(!1),w(!1)),()=>{document.body.style.overflow=""}),[e]),o.useEffect(()=>{if(!e)return;const ee=U=>{if(U.key==="Escape"&&!Q){if(L){D();return}j()}};return window.addEventListener("keydown",ee),()=>window.removeEventListener("keydown",ee)},[D,Q,L,e,j]),!x)return null;const te=N!==void 0?N:c?"Guardando…":null;return ct.createPortal(t.jsxs("div",{"aria-hidden":!e,"data-bonsaif-overlay":e?"true":void 0,className:`fixed inset-0 z-[1000] flex transition-opacity duration-300 ${e?"opacity-100":"opacity-0 pointer-events-none"}`,children:[t.jsx("div",{className:`absolute inset-0 ${gs}`,onClick:j}),t.jsxs("div",{className:`absolute inset-y-0 right-0 flex flex-col shadow-2xl transition-transform duration-300 ${e?"translate-x-0":"translate-x-full"}`,style:{width:`min(100vw, ${b}px)`,background:"var(--bg-card)",borderLeft:"1px solid var(--border)"},children:[t.jsxs("div",{className:"flex items-center justify-between px-6 py-4 flex-shrink-0",style:{borderBottom:"1px solid var(--border)"},children:[t.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[t.jsx(Ue,{variant:"icon",onClick:j,title:"Cerrar",disabled:Q,children:t.jsx(q.HiXMark,{className:"w-5 h-5"})}),s&&t.jsx("div",{className:"flex-shrink-0",children:s}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("h3",{className:"text-base font-semibold truncate",style:{color:"var(--text-main)"},children:n}),a&&t.jsx("p",{className:"text-xs truncate",style:{color:"var(--text-muted)"},children:a})]})]}),(u||i)&&t.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[u,i&&t.jsxs(t.Fragment,{children:[t.jsx(Ue,{variant:"secondary",size:"sm",onClick:j,disabled:Q,style:{background:"var(--bg-input)"},children:"Cancelar"}),t.jsx(Ue,{variant:"primary",size:"sm",icon:t.jsx(Li.FiSave,{className:"w-4 h-4"}),onClick:i,loading:c,disabled:d||Q,title:l})]})]})]}),t.jsx("div",{"data-drawer-scroll":"true",className:m,children:T}),Q&&t.jsx("div",{className:"absolute inset-0 z-[1002] flex cursor-not-allowed items-center justify-center p-6",style:{background:"color-mix(in srgb, var(--bg-card, #ffffff) 72%, transparent)",backdropFilter:"blur(3px)"},role:"status","aria-live":"polite","aria-busy":"true",children:te?t.jsxs("div",{className:"flex max-w-xs flex-col items-center gap-3 text-center",children:[t.jsx("div",{className:"h-9 w-9 animate-spin rounded-full border-2 border-[var(--border)] border-t-[var(--primary)]","aria-hidden":!0}),t.jsx("p",{className:"text-sm font-semibold text-[var(--text-main)]",children:te})]}):null})]}),L&&t.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":g,className:"fixed inset-0 z-[1001] flex items-center justify-center p-4",children:[t.jsx("div",{className:`absolute inset-0 ${gs} transition-opacity duration-200 ease-out ${W?"opacity-100":"opacity-0"}`,onClick:D}),t.jsxs("div",{className:`relative z-10 w-full max-w-sm rounded-2xl border p-6 shadow-2xl transition-[opacity,transform] duration-200 ease-out ${W?"translate-y-0 scale-100 opacity-100":"translate-y-2 scale-[0.96] opacity-0"}`,style:{background:"var(--bg-card, #ffffff)",borderColor:"var(--border, #d8e1dc)"},children:[t.jsx(Ue,{variant:"icon",onClick:D,className:"absolute right-3 top-3 h-7 w-7 hover:opacity-70",style:{color:"var(--text-muted, #6b7f78)"},"aria-label":h,children:t.jsx(q.HiXMark,{className:"h-4 w-4"})}),t.jsx("div",{className:"mb-4 flex h-11 w-11 items-center justify-center rounded-xl",style:{background:"var(--warning-bg, #fff7ed)"},children:t.jsx(q.HiExclamationTriangle,{className:"h-5 w-5",style:{color:"var(--warning, #d97706)"}})}),t.jsx("h2",{className:"mb-1 text-base font-semibold",style:{color:"var(--text-main, #0f2f2c)"},children:g}),t.jsx("p",{className:"text-sm",style:{color:"var(--text-muted, #6b7f78)"},children:v}),t.jsxs("div",{className:"mt-6 flex gap-2",children:[t.jsx(Ue,{variant:"secondary",onClick:D,className:"flex-1 border",style:{background:"var(--bg-input, #f7faf8)",borderColor:"var(--border, #d8e1dc)",color:"var(--text-main, #0f2f2c)"},children:h}),t.jsx(Ue,{variant:"secondary",onClick:se,className:"flex-1 border",style:{background:"var(--warning, #d97706)",borderColor:"transparent",color:"#fff",boxShadow:"0 10px 22px rgba(217, 119, 6, 0.22)"},children:k})]})]})]})]}),document.body)}const sd=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,ld=/^\+?[0-9\s().-]+$/,id=7,cd=15;function $t(e){return e==null||String(e).trim()===""}function vs(e){return typeof e=="number"?e:typeof e=="string"&&e.trim()!==""?Number(e):Number.NaN}function qa(e){return $t(e)?!1:sd.test(String(e))}function Ua(e){if($t(e))return!1;const r=String(e),n=r.replace(/\D/g,"");return ld.test(r)&&n.length>=id&&n.length<=cd}function dd(e="Este campo es requerido."){return r=>$t(r)?e:void 0}function ud(e="Ingresa un correo valido."){return r=>$t(r)||qa(r)?void 0:e}function fd(e="Ingresa un telefono valido."){return r=>$t(r)||Ua(r)?void 0:e}function bd(e,r){return n=>$t(n)||String(n).length>=e?void 0:r??`Debe tener al menos ${e} caracteres.`}function md(e,r){return n=>$t(n)||String(n).length<=e?void 0:r??`Debe tener ${e} caracteres o menos.`}function pd(e,r){return n=>{if($t(n))return;const a=vs(n);return Number.isFinite(a)&&a>=e?void 0:r??`Debe ser mayor o igual a ${e}.`}}function hd(e,r){return n=>{if($t(n))return;const a=vs(n);return Number.isFinite(a)&&a<=e?void 0:r??`Debe ser menor o igual a ${e}.`}}function gd(e,r="El formato no es valido."){return n=>$t(n)||e.test(String(n))?void 0:r}function vd(e,r){const n={};for(const a of Object.keys(r)){const s=r[a];if(!s)continue;const l=Array.isArray(s)?s:[s];for(const i of l){const c=i(e[a],e);if(c){n[a]=c;break}}}return{valid:Object.keys(n).length===0,errors:n}}var ys={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},xs=o.createContext&&o.createContext(ys),yd=["attr","size","title"];function xd(e,r){if(e==null)return{};var n,a,s=wd(e,r);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a<l.length;a++)n=l[a],r.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(s[n]=e[n])}return s}function wd(e,r){if(e==null)return{};var n={};for(var a in e)if({}.hasOwnProperty.call(e,a)){if(r.indexOf(a)!==-1)continue;n[a]=e[a]}return n}function An(){return An=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var a in n)({}).hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e},An.apply(null,arguments)}function ws(e,r){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);r&&(a=a.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,a)}return n}function Ln(e){for(var r=1;r<arguments.length;r++){var n=arguments[r]!=null?arguments[r]:{};r%2?ws(Object(n),!0).forEach(function(a){Nd(e,a,n[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ws(Object(n)).forEach(function(a){Object.defineProperty(e,a,Object.getOwnPropertyDescriptor(n,a))})}return e}function Nd(e,r,n){return(r=kd(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function kd(e){var r=Sd(e,"string");return typeof r=="symbol"?r:r+""}function Sd(e,r){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var a=n.call(e,r);if(typeof a!="object")return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function Ns(e){return e&&e.map((r,n)=>o.createElement(r.tag,Ln({key:n},r.attr),Ns(r.child)))}function Va(e){return r=>o.createElement(Cd,An({attr:Ln({},e.attr)},r),Ns(e.child))}function Cd(e){var r=n=>{var{attr:a,size:s,title:l}=e,i=xd(e,yd),c=s||n.size||"1em",d;return n.className&&(d=n.className),e.className&&(d=(d?d+" ":"")+e.className),o.createElement("svg",An({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,a,i,{className:d,style:Ln(Ln({color:e.color||n.color},n.style),e.style),height:c,width:c,xmlns:"http://www.w3.org/2000/svg"}),l&&o.createElement("title",null,l),e.children)};return xs!==void 0?o.createElement(xs.Consumer,null,n=>r(n)):r(ys)}function ks(e){return Va({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Zm-8-80V80a8,8,0,0,1,16,0v56a8,8,0,0,1-16,0Zm20,36a12,12,0,1,1-12-12A12,12,0,0,1,140,172Z"},child:[]}]})(e)}function Ed(e){return Va({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M247.31,124.76c-.35-.79-8.82-19.58-27.65-38.41C194.57,61.26,162.88,48,128,48S61.43,61.26,36.34,86.35C17.51,105.18,9,124,8.69,124.76a8,8,0,0,0,0,6.5c.35.79,8.82,19.57,27.65,38.4C61.43,194.74,93.12,208,128,208s66.57-13.26,91.66-38.34c18.83-18.83,27.3-37.61,27.65-38.4A8,8,0,0,0,247.31,124.76ZM128,192c-30.78,0-57.67-11.19-79.93-33.25A133.47,133.47,0,0,1,25,128,133.33,133.33,0,0,1,48.07,97.25C70.33,75.19,97.22,64,128,64s57.67,11.19,79.93,33.25A133.46,133.46,0,0,1,231.05,128C223.84,141.46,192.43,192,128,192Zm0-112a48,48,0,1,0,48,48A48.05,48.05,0,0,0,128,80Zm0,80a32,32,0,1,1,32-32A32,32,0,0,1,128,160Z"},child:[]}]})(e)}function Md(e){return Va({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M228,175a8,8,0,0,1-10.92-3l-19-33.2A123.23,123.23,0,0,1,162,155.46l5.87,35.22a8,8,0,0,1-6.58,9.21A8.4,8.4,0,0,1,160,200a8,8,0,0,1-7.88-6.69l-5.77-34.58a133.06,133.06,0,0,1-36.68,0l-5.77,34.58A8,8,0,0,1,96,200a8.4,8.4,0,0,1-1.32-.11,8,8,0,0,1-6.58-9.21L94,155.46a123.23,123.23,0,0,1-36.06-16.69L39,172A8,8,0,1,1,25.06,164l20-35a153.47,153.47,0,0,1-19.3-20A8,8,0,1,1,38.22,99c16.6,20.54,45.64,45,89.78,45s73.18-24.49,89.78-45A8,8,0,1,1,230.22,109a153.47,153.47,0,0,1-19.3,20l20,35A8,8,0,0,1,228,175Z"},child:[]}]})(e)}function xr({content:e,ariaLabel:r="Más información",className:n=""}){return t.jsx(Yt,{as:"span",content:e,className:`inline-flex shrink-0 align-middle text-[var(--text-muted)] outline-none transition-colors hover:text-[var(--primary)] focus-visible:text-[var(--primary)] ${n}`,children:t.jsx("span",{tabIndex:0,role:"img","aria-label":r,className:"inline-flex items-center justify-center outline-none",children:t.jsx(q.HiInformationCircle,{className:"h-3.5 w-3.5"})})})}function wr({error:e,helperText:r,helperDisplay:n="inline"}){return e?t.jsx("span",{className:"text-xs font-medium normal-case text-[var(--danger)]",children:e}):r&&n!=="tooltip"?t.jsx("span",{className:"text-xs font-medium normal-case text-[var(--text-muted)]",children:r}):null}function Dn({className:e="",...r}){return t.jsx("input",{...r,className:`h-10 rounded-lg border border-[var(--border)] bg-[var(--bg-input)] px-2.5 py-1.5 text-sm text-[var(--text-main)] outline-none placeholder:text-[var(--text-muted)] transition-colors focus:border-[var(--primary)] ${e}`})}function Ya({label:e,containerClassName:r="",helperText:n,helperDisplay:a="inline",error:s,errorDisplay:l="inline",errorTooltipLabel:i="Error de validacion",labelAction:c,floatingLabel:d=!1,showPasswordToggle:u=!0,nativeValidation:m=!1,className:b="",required:f,...g}){const[v,k]=o.useState(()=>!!g.autoFocus),[h,A]=o.useState(!1),$=g.type==="password"&&u,N=$&&h?"text":g.type,T=!!s,x=T&&l!=="tooltip",y=T&&l!=="inline",L=!!n&&a==="tooltip"&&!x,w=m?f:void 0,W=T?"border-[var(--danger)] focus:border-[var(--danger)]":"",X=y?$?"pr-20":"pr-10":$?"pr-10":"",Z=g.value!==void 0?String(g.value).length>0:g.defaultValue!==void 0&&String(g.defaultValue).length>0,D=v||Z,Q={top:D?7:12,color:v?"var(--primary)":"var(--text-muted)",fontSize:D?10:13,fontWeight:D?600:400,textTransform:D?"uppercase":"none"},j=J=>{var ce;k(!0),(ce=g.onFocus)==null||ce.call(g,J)},se=J=>{var ce;k(!1),(ce=g.onBlur)==null||ce.call(g,J)},te=$?t.jsxs("button",{type:"button","aria-label":h?"Ocultar contraseña":"Mostrar contraseña","aria-pressed":h,className:"absolute right-2.5 top-1/2 flex h-7 w-7 -translate-y-1/2 items-center justify-center rounded-md text-[var(--text-muted)] transition-colors duration-200 hover:text-[var(--primary)] focus:outline-none",tabIndex:-1,onClick:()=>A(J=>!J),children:[t.jsx("span",{"aria-hidden":"true",className:`absolute inset-0 flex items-center justify-center transition-[opacity,transform] duration-200 ease-out ${h?"scale-y-0 rotate-[-8deg] opacity-0":"scale-y-100 rotate-0 opacity-100"}`,children:t.jsx(Ed,{className:"h-[18px] w-[18px]"})}),t.jsx("span",{"aria-hidden":"true",className:`absolute inset-0 flex items-center justify-center transition-[opacity,transform] duration-200 ease-out ${h?"scale-y-100 rotate-0 opacity-100":"scale-y-0 rotate-[8deg] opacity-0"}`,children:t.jsx(Md,{className:"h-[18px] w-[18px]"})})]}):null,ee=y?t.jsx(Yt,{as:"span",content:s,className:`absolute top-1/2 flex h-7 w-7 -translate-y-1/2 items-center justify-center rounded-md text-[var(--danger)] outline-none transition-colors hover:bg-[var(--danger-bg)] focus-visible:bg-[var(--danger-bg)] ${$?"right-10":"right-2.5"}`,children:t.jsx("span",{tabIndex:0,role:"img","aria-label":i,className:"flex h-full w-full items-center justify-center outline-none",children:t.jsx(ks,{className:"h-[18px] w-[18px]"})})}):null,U=t.jsx(wr,{error:x?s:void 0,helperText:n,helperDisplay:a});return d?t.jsxs("label",{className:`flex flex-col gap-2 ${r}`,children:[t.jsxs("span",{className:"relative block",children:[t.jsx(Dn,{...g,type:N,required:w,placeholder:" ","aria-invalid":T||g["aria-invalid"],"data-has-value":Z?"true":void 0,className:`h-11 w-full pt-5 ${X} ${W} ${b}`,onFocus:j,onBlur:se}),t.jsxs("span",{className:"pointer-events-none absolute left-3 transition-all duration-150",style:Q,children:[e,f&&t.jsx("span",{className:"ml-1 text-[var(--danger)]",children:"*"})]}),c&&t.jsx("span",{className:"absolute right-2 transition-all duration-150",style:{top:D?7:12},children:c}),ee,te]}),U]}):t.jsxs("label",{className:`flex flex-col gap-2 ${r}`,children:[t.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-semibold uppercase text-[var(--text-muted)]",children:[t.jsx("span",{children:e}),f&&t.jsx("span",{className:"text-[var(--danger)]",children:"*"}),L?t.jsx(xr,{content:n}):null,c&&t.jsx("span",{className:"ml-auto normal-case",children:c})]}),$?t.jsxs("span",{className:"relative block",children:[t.jsx(Dn,{...g,type:N,required:w,"aria-invalid":T||g["aria-invalid"],className:`w-full ${X} ${W} ${b}`,onFocus:j,onBlur:se}),ee,te]}):t.jsxs("span",{className:"relative block",children:[t.jsx(Dn,{...g,required:w,"aria-invalid":T||g["aria-invalid"],className:`w-full ${X} ${W} ${b}`}),ee]}),U]})}function Ss(e){return e==null?"":String(e)}function Td({autoComplete:e="email",inputMode:r="email",validate:n=!0,invalidMessage:a="Ingresa un correo valido.",errorDisplay:s="tooltip",error:l,value:i,defaultValue:c,onChange:d,...u}){const[m,b]=o.useState(()=>Ss(c)),f=i!==void 0?Ss(i):m,g=n&&f.length>0&&!qa(f)?a:void 0,v=k=>{i===void 0&&b(k.currentTarget.value),d==null||d(k)};return t.jsx(Ya,{...u,value:i,defaultValue:c,type:"text",inputMode:r,autoComplete:e,error:l??g,errorDisplay:s,onChange:v})}const $d={sm:"min-h-[160px] p-4",md:"min-h-[220px] p-6",lg:"min-h-[300px] p-8"};function Ad({title:e="Sin resultados",description:r,icon:n=t.jsx(q.HiInbox,{className:"h-5 w-5"}),action:a,secondaryAction:s,size:l="md",className:i=""}){return t.jsx("div",{className:`flex items-center justify-center rounded-lg border border-[var(--border)] bg-[var(--bg-card)] text-center ${$d[l]} ${i}`,children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-3",children:[n&&t.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg border border-[var(--border)] bg-[var(--bg-input)] text-[var(--text-muted)]",children:n}),t.jsxs("div",{className:"space-y-1",children:[e&&t.jsx("h3",{className:"text-sm font-semibold text-[var(--text-main)]",children:e}),r&&t.jsx("div",{className:"text-sm leading-5 text-[var(--text-muted)]",children:r})]}),(a||s)&&t.jsxs("div",{className:"mt-1 flex flex-wrap items-center justify-center gap-2",children:[s,a]})]})})}const Ld={sm:"min-h-[112px] p-4",md:"min-h-[148px] p-5",lg:"min-h-[184px] p-6"};function Dd(e){if(e===0)return"0 B";const r=["B","KB","MB","GB"],n=Math.min(Math.floor(Math.log(e)/Math.log(1024)),r.length-1),a=e/1024**n;return`${a>=10||n===0?a.toFixed(0):a.toFixed(1)} ${r[n]}`}function Cs(e,r){return r?r.split(",").map(n=>n.trim().toLowerCase()).filter(Boolean).some(n=>{const a=e.name.toLowerCase(),s=e.type.toLowerCase();return n.startsWith(".")?a.endsWith(n):n.endsWith("/*")?s.startsWith(n.slice(0,-1)):s===n}):!0}function Id(e,r,n){return r?n===void 0?e:e.slice(0,Math.max(0,n)):e.slice(0,1)}function Od({label:e,helperText:r,helperDisplay:n="inline",error:a,labelAction:s,value:l,defaultValue:i=[],onFilesChange:c,onRejectedFiles:d,multiple:u=!1,maxFiles:m,appendFiles:b=!1,showFileList:f=!0,clearable:g=!0,browseLabel:v="Buscar archivos",dropLabel:k="Suelta los archivos aqui",emptyLabel:h="Arrastra y suelta archivos",emptyDescription:A="o haz click para buscarlos en tu equipo",selectedLabel:$="Archivos seleccionados",size:N="md",containerClassName:T="",dropzoneClassName:x="",fileListClassName:y="",className:L="",id:w,accept:W,disabled:X,required:Z,...D}){const Q=o.useId(),j=w??Q,se=o.useRef(null),[te,ee]=o.useState(!1),[U,J]=o.useState(i),ce=l??U,C=!!a,_=!!r&&n==="tooltip"&&!C,ae=g&&ce.length>0&&!X,B=(z,de)=>{l===void 0&&J(z),c==null||c(z,de)},I=(z,de)=>{const he=z.filter($e=>Cs($e,W)),ie=z.filter($e=>!Cs($e,W)),ge=b?[...ce,...he]:he,Me=Id(ge,u,m);ie.length>0&&(d==null||d(ie)),B(Me,de)},E=()=>{var z;X||(z=se.current)==null||z.click()},oe=z=>{I(Array.from(z.target.files??[]),z),z.target.value=""},K=z=>{z.preventDefault(),X||ee(!0)},Y=z=>{z.currentTarget.contains(z.relatedTarget)||ee(!1)},S=z=>{z.preventDefault(),ee(!1),!X&&I(Array.from(z.dataTransfer.files),z)},H=z=>{z.key!=="Enter"&&z.key!==" "||(z.preventDefault(),E())},O=z=>{B(ce.filter((de,he)=>he!==z))},re=()=>{B([])};return t.jsxs("div",{className:`flex flex-col gap-2 ${T}`,children:[(e||s||_)&&t.jsxs("div",{className:"inline-flex items-center gap-1 text-xs font-semibold uppercase text-[var(--text-muted)]",children:[e&&t.jsx("span",{children:e}),Z&&t.jsx("span",{className:"text-[var(--danger)]",children:"*"}),_?t.jsx(xr,{content:r}):null,s&&t.jsx("span",{className:"ml-auto normal-case",children:s})]}),t.jsx("input",{...D,ref:se,id:j,type:"file",accept:W,multiple:u,disabled:X,required:Z&&ce.length===0,"aria-invalid":C||D["aria-invalid"],className:"sr-only",onChange:oe}),t.jsxs("div",{role:"button",tabIndex:X?-1:0,"aria-controls":j,"aria-disabled":X||void 0,"aria-invalid":C||void 0,className:`flex cursor-pointer flex-col items-center justify-center gap-3 rounded-lg border border-dashed bg-[var(--bg-card)] text-center outline-none transition-colors focus:border-[var(--primary)] focus:bg-[var(--bg-input)] ${Ld[N]} ${te?"border-[var(--primary)] bg-[var(--bg-input)]":C?"border-[var(--danger)]":"border-[var(--border)]"} ${X?"cursor-not-allowed opacity-60":"hover:border-[var(--primary)] hover:bg-[var(--bg-input)]"} ${x} ${L}`,onClick:E,onDragOver:K,onDragLeave:Y,onDrop:S,onKeyDown:H,children:[t.jsx("span",{className:"flex h-10 w-10 items-center justify-center rounded-lg border border-[var(--border)] bg-[var(--bg-input)] text-[var(--text-muted)]",children:t.jsx(q.HiArrowUpTray,{className:"h-5 w-5"})}),t.jsxs("span",{className:"space-y-1",children:[t.jsx("span",{className:"block text-sm font-semibold text-[var(--text-main)]",children:te?k:h}),A&&t.jsx("span",{className:"block text-sm text-[var(--text-muted)]",children:A})]}),v&&t.jsx("span",{className:"inline-flex h-9 items-center justify-center rounded-lg border border-[var(--border)] bg-[var(--bg-card)] px-3 text-xs font-semibold text-[var(--text-main)] shadow-sm shadow-black/5 transition-colors",children:v})]}),f&&ce.length>0&&t.jsxs("div",{className:`rounded-lg border border-[var(--border)] bg-[var(--bg-card)] ${y}`,children:[t.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--border)] px-3 py-2",children:[t.jsx("span",{className:"text-xs font-semibold uppercase text-[var(--text-muted)]",children:$}),ae&&t.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-input)] hover:text-[var(--danger)] focus:outline-none","aria-label":"Quitar todos los archivos",onClick:re,children:t.jsx(q.HiTrash,{className:"h-4 w-4"})})]}),t.jsx("ul",{className:"divide-y divide-[var(--border)]",children:ce.map((z,de)=>t.jsxs("li",{className:"flex items-center gap-3 px-3 py-2",children:[t.jsx("span",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-[var(--bg-input)] text-[var(--text-muted)]",children:t.jsx(q.HiDocument,{className:"h-4 w-4"})}),t.jsxs("span",{className:"min-w-0 flex-1 text-left",children:[t.jsx("span",{className:"block truncate text-sm font-medium text-[var(--text-main)]",children:z.name}),t.jsx("span",{className:"block text-xs text-[var(--text-muted)]",children:Dd(z.size)})]}),!X&&t.jsx("button",{type:"button",className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-input)] hover:text-[var(--danger)] focus:outline-none","aria-label":`Quitar ${z.name}`,onClick:()=>O(de),children:t.jsx(q.HiXMark,{className:"h-4 w-4"})})]},`${z.name}-${z.lastModified}-${de}`))})]}),t.jsx(wr,{error:a,helperText:r,helperDisplay:n})]})}const Hd=[{value:"texto",label:"texto"},{value:"numero",label:"número"},{value:"fecha",label:"fecha"},{value:"booleano",label:"booleano"},{value:"email",label:"email"},{value:"telefono",label:"teléfono"},{value:"select",label:"select"},{value:"textarea",label:"textarea"},{value:"archivo",label:"archivo"},{value:"imagen",label:"imagen"}];function Bd({fields:e,title:r="Layout",fieldTypes:n=Hd,saveLabel:a="Guardar",allowAddField:s=!1,addFieldPlaceholder:l="Nuevo campo",addFieldLabel:i="Anadir",loading:c=!1,onSave:d,onChange:u}){const[m,b]=o.useState(()=>e.map(N=>({key:!1,type:"",...N}))),[f,g]=o.useState(""),[v,k]=o.useState(""),h=o.useCallback((N,T)=>{b(x=>{const y=x.map((L,w)=>w===N?{...L,...T}:L);return u==null||u(y),y})},[u]),A=o.useCallback(()=>{d==null||d(m)},[m,d]),$=o.useCallback(()=>{var y;const N=f.trim();if(!N){k("Ingresa un nombre de campo.");return}if(m.some(L=>L.name.toLowerCase()===N.toLowerCase())){k("Ese campo ya existe en el arreglo.");return}const x={name:N,key:!1,type:((y=n[0])==null?void 0:y.value)??""};b(L=>{const w=[...L,x];return u==null||u(w),w}),g(""),k("")},[n,m,f,u]);return t.jsxs("div",{className:"flex flex-col rounded-xl border shadow-sm",style:{borderColor:"var(--border)",background:"var(--bg-card)",color:"var(--text-main)"},children:[t.jsx("div",{className:"border-b px-6 py-4",style:{borderColor:"var(--border)"},children:t.jsx("span",{className:"text-base font-semibold",style:{color:"var(--text-main)"},children:r})}),t.jsxs("div",{className:"grid grid-cols-[1fr_80px_1fr] gap-4 border-b px-6 py-2 text-xs font-medium uppercase tracking-wide",style:{borderColor:"var(--border)",color:"var(--text-muted)"},children:[t.jsx("span",{children:"Campo"}),t.jsx("span",{className:"text-center",children:"Llave"}),t.jsx("span",{children:"Tipo de Campo"})]}),t.jsxs("div",{className:"max-h-[420px] overflow-y-auto",children:[m.map((N,T)=>t.jsxs("div",{className:"grid grid-cols-[1fr_80px_1fr] items-center gap-4 border-b px-6 py-3 last:border-0 hover:bg-[var(--bg-input)] transition-colors",style:{borderColor:"var(--border)"},children:[t.jsx("span",{className:"text-sm font-medium",style:{color:"var(--text-main)"},children:N.name}),t.jsx("div",{className:"flex justify-center",children:t.jsx(Nn,{size:"sm",checked:N.key??!1,onChange:x=>h(T,{key:x.target.checked}),"aria-label":`${N.name} es clave`})}),t.jsx(ar,{value:N.type??"",onChange:x=>h(T,{type:x}),options:n,placeholder:"—",emptyLabel:"—",height:36,searchable:!1,ariaLabel:`Tipo de ${N.name}`})]},N.name)),m.length===0&&t.jsx("p",{className:"px-6 py-8 text-center text-sm",style:{color:"var(--text-muted)"},children:"No hay campos disponibles."})]}),t.jsx("div",{className:"flex justify-end border-t px-6 py-4",style:{borderColor:"var(--border)"},children:t.jsxs("div",{className:"w-full space-y-2",children:[s&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("input",{type:"text",value:f,onChange:N=>{g(N.currentTarget.value),v&&k("")},onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),$())},placeholder:l,className:"min-w-0 flex-1 rounded-lg border px-3 py-2 text-sm outline-none transition-colors",style:{borderColor:"var(--border)",background:"var(--bg-input)",color:"var(--text-main)"},"aria-label":"Nombre del nuevo campo"}),t.jsx(Ue,{variant:"secondary",onClick:$,height:36,padding:"0 12px",children:i})]}),v&&t.jsx("p",{className:"text-xs",style:{color:"var(--danger)"},children:v})]}),t.jsx("div",{className:"flex justify-end",children:t.jsx(Ue,{variant:"primary",onClick:A,disabled:c,loading:c,children:a})})]})})]})}function In({label:e,children:r,helperText:n,helperDisplay:a="inline",error:s,labelAction:l,required:i=!1,className:c="",contentClassName:d=""}){const u=!!n&&a==="tooltip"&&!s;return t.jsxs("label",{className:`flex flex-col gap-2 ${c}`,children:[(e||l||u)&&t.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-semibold uppercase text-[var(--text-muted)]",children:[e&&t.jsx("span",{children:e}),i&&t.jsx("span",{className:"text-[var(--danger)]",children:"*"}),u?t.jsx(xr,{content:n}):null,l&&t.jsx("span",{className:"ml-auto normal-case",children:l})]}),t.jsx("span",{className:`block ${d}`,children:r}),t.jsx(wr,{error:s,helperText:n,helperDisplay:a})]})}function Fd(e){return Array.from(e.querySelectorAll("img")).filter(r=>!!(r.currentSrc||r.src||"").trim())}function Es(e,r){const n=e.target;if(!(n instanceof HTMLImageElement))return!1;const a=e.currentTarget,s=Fd(a),l=s.indexOf(n);if(l<0)return!1;e.preventDefault(),e.stopPropagation();const i=n.getBoundingClientRect();return r(s.map(c=>({src:c.currentSrc||c.src,alt:c.alt||void 0})),l,{left:i.left,top:i.top,width:i.width,height:i.height}),!0}const St=260,Nr=420,Xa=380,At="cubic-bezier(0.22, 1, 0.36, 1)",Pd="cubic-bezier(0.16, 1, 0.3, 1)",Ka="cubic-bezier(0.22, 1, 0.36, 1)",_d="cubic-bezier(0.22, 1, 0.36, 1)",zd=8,Wd=1,jd=1.25,Ga={background:"color-mix(in srgb, var(--bg-card) 90%, transparent)",border:"1px solid var(--border)",boxShadow:"0 10px 28px color-mix(in srgb, var(--bg-main) 28%, transparent), inset 0 1px 0 color-mix(in srgb, var(--bg-card) 55%, transparent)",color:"var(--text-main)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},qd="color-mix(in srgb, var(--bg-card) 88%, var(--primary) 12%)",Za=10;function tn(e,r,n){return Math.min(n,Math.max(r,e))}function Ud(e){return!e||e.width<1||e.height<1?null:{left:e.left,top:e.top,width:e.width,height:e.height}}function Ms(e,r){if(r.width<1||r.height<1)return{dx:0,dy:0,scale:1};const n=Math.min(e.width/r.width,e.height/r.height),a=e.left+e.width/2-(r.left+r.width/2),s=e.top+e.height/2-(r.top+r.height/2);return{dx:a,dy:s,scale:Number.isFinite(n)?n:1}}function kr({label:e,onClick:r,children:n,disabled:a,size:s="md"}){const l=s==="lg"?44:40;return t.jsx("button",{type:"button","aria-label":e,title:e,disabled:a,onClick:i=>{i.stopPropagation(),r()},className:"inline-flex items-center justify-center rounded-full disabled:cursor-not-allowed disabled:opacity-35",style:{...Ga,width:l,height:l,transition:"background 160ms ease, transform 160ms cubic-bezier(0.22, 1, 0.36, 1), opacity 160ms ease"},onMouseEnter:i=>{a||(i.currentTarget.style.background=qd,i.currentTarget.style.transform="scale(1.06)")},onMouseLeave:i=>{i.currentTarget.style.background=String(Ga.background??""),i.currentTarget.style.transform="scale(1)"},onMouseDown:i=>{a||(i.currentTarget.style.transform="scale(0.94)")},onMouseUp:i=>{a||(i.currentTarget.style.transform="scale(1.06)")},children:n})}function Ts({open:e,onClose:r,slides:n,index:a,onIndexChange:s,originRect:l=null,maxZoom:i=zd,minZoom:c=Wd,zoomStep:d=jd,closeOnBackdrop:u=!0,closeOnEscape:m=!0,showCounter:b=!0,showZoomControls:f=!0,loop:g=!0,showThumbnails:v=!0,zIndex:k=1100,ariaLabel:h="Visor de imagen"}){const[A,$]=o.useState(!1),[N,T]=o.useState(!1),[x,y]=o.useState(a??0),[L,w]=o.useState(1),[W,X]=o.useState({x:0,y:0}),[Z,D]=o.useState({opacity:1,x:0,scale:1,blur:0,animate:!1}),[Q,j]=o.useState({dx:0,dy:0,scale:1,animate:!1,enabled:!1}),[se,te]=o.useState(!1),ee=o.useRef(null),U=o.useRef(null),J=o.useRef(null),ce=o.useRef(null),C=o.useRef(null),_=o.useRef(!1),ae=o.useRef(!1),B=o.useRef(null),I=o.useRef(null),E=o.useRef(null),oe=o.useRef(null),K=o.useRef(null),Y=o.useRef(a??0),S=a??x,H=n.length===0?0:tn(S,0,Math.max(0,n.length-1)),O=n[H],re=n.length>1,z=Math.max(c,i),de=v&&re,he=o.useCallback(ue=>{if(n.length===0)return;const pe=n.length-1,Le=g?(ue%n.length+n.length)%n.length:tn(ue,0,pe);a===void 0&&y(Le),s==null||s(Le)},[a,g,s,n.length]),ie=o.useCallback(()=>{w(1),X({x:0,y:0})},[]),ge=o.useCallback((ue,pe)=>{if(pe<=c+.001)return{x:0,y:0};const Le=oe.current,He=K.current;if(!Le||!He)return ue;const Ie=Le.getBoundingClientRect(),tt=He.offsetWidth*pe,at=He.offsetHeight*pe,We=Math.max(0,(tt-Ie.width)/2+Ie.width*.15),Ke=Math.max(0,(at-Ie.height)/2+Ie.height*.15);return{x:tn(ue.x,-We,We),y:tn(ue.y,-Ke,Ke)}},[c]),Me=o.useCallback(()=>{$(!1),j({dx:0,dy:0,scale:1,animate:!1,enabled:!1}),ce.current=null,C.current=null,_.current=!1,ae.current=!1,B.current&&(clearTimeout(B.current),B.current=null)},[]),$e=o.useCallback(()=>{if(_.current)return;_.current=!0,T(!1),ie();const ue=ce.current,pe=ue!=null&&C.current!=null&&C.current===H;if(ue&&pe){J.current!=null&&cancelAnimationFrame(J.current),J.current=requestAnimationFrame(()=>{J.current=requestAnimationFrame(()=>{const Le=K.current;if(!Le){J.current=null,ee.current&&clearTimeout(ee.current),ee.current=setTimeout(Me,St+40);return}const He=Le.getBoundingClientRect(),Ie=Ms(ue,He);j({enabled:!0,dx:0,dy:0,scale:1,animate:!1}),J.current=requestAnimationFrame(()=>{j({enabled:!0,dx:Ie.dx,dy:Ie.dy,scale:Ie.scale,animate:!0}),J.current=null})})}),ee.current&&clearTimeout(ee.current),ee.current=setTimeout(Me,Nr+80);return}j({dx:0,dy:0,scale:1,animate:!1,enabled:!1}),ee.current&&clearTimeout(ee.current),ee.current=setTimeout(Me,St+40)},[Me,ie,H]);o.useEffect(()=>(e?(ee.current&&clearTimeout(ee.current),B.current&&(clearTimeout(B.current),B.current=null),_.current=!1,ae.current=!1,ce.current=Ud(l),C.current=ce.current!=null?a??x:null,$(!0),T(!1),ce.current?j({dx:0,dy:0,scale:1,animate:!1,enabled:!0}):(C.current=null,requestAnimationFrame(()=>requestAnimationFrame(()=>{T(!0),j({dx:0,dy:0,scale:1,animate:!1,enabled:!1})})))):A&&$e(),()=>{ee.current&&clearTimeout(ee.current),J.current!=null&&cancelAnimationFrame(J.current)}),[e]);const Dt=o.useCallback(()=>{if(!e||_.current||ae.current)return;const ue=ce.current,pe=K.current;if(!ue||!pe){ue||(T(!0),ae.current=!0);return}const Le=pe.getBoundingClientRect();if(Le.width<2||Le.height<2)return;ae.current=!0;const He=Ms(ue,Le);j({enabled:!0,dx:He.dx,dy:He.dy,scale:He.scale,animate:!1}),J.current!=null&&cancelAnimationFrame(J.current),J.current=requestAnimationFrame(()=>{J.current=requestAnimationFrame(()=>{j({enabled:!0,dx:0,dy:0,scale:1,animate:!0}),T(!0),J.current=null,B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{j({dx:0,dy:0,scale:1,animate:!1,enabled:!1}),B.current=null},Nr+20)})})},[e]);o.useLayoutEffect(()=>{!A||!e||!ce.current||ae.current||Dt()},[A,e,Dt]),o.useEffect(()=>{!e||_.current||C.current!=null&&C.current!==H&&j(ue=>ue.enabled?{dx:0,dy:0,scale:1,animate:!1,enabled:!1}:ue)},[e,H]),o.useEffect(()=>{if(!e)return;const ue=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=ue}},[e]),o.useEffect(()=>{e&&ie()},[e,H,ie]),o.useEffect(()=>{a!==void 0&&y(a)},[a]),o.useEffect(()=>{if(!e){Y.current=H,D({opacity:1,x:0,scale:1,blur:0,animate:!1});return}const ue=Y.current;if(ue===H)return;Y.current=H;const pe=n.length;let Le=1;if(pe>1){const He=(ue+1)%pe===H,Ie=(ue-1+pe)%pe===H;Ie&&!He?Le=-1:He&&!Ie?Le=1:Le=H>ue?1:-1}return U.current!=null&&(cancelAnimationFrame(U.current),U.current=null),D({opacity:0,x:Le*56,scale:.94,blur:8,animate:!1}),U.current=requestAnimationFrame(()=>{U.current=requestAnimationFrame(()=>{D({opacity:1,x:0,scale:1,blur:0,animate:!0}),U.current=null})}),()=>{U.current!=null&&(cancelAnimationFrame(U.current),U.current=null)}},[e,H,n.length]);const ut=L<=c+.001&&Math.abs(W.x)<.5&&Math.abs(W.y)<.5,Re=o.useCallback((ue,pe,Le)=>{w(He=>{const Ie=tn(ue,c,z);if(Math.abs(Ie-He)<1e-4)return He;const tt=Ie/He,at=Ie<He;return Ie<=c+.001?(X({x:0,y:0}),c):(X(We=>{let Ke=We;if(typeof pe=="number"&&typeof Le=="number"&&oe.current&&!at){const Ge=oe.current.getBoundingClientRect(),Ae=pe-Ge.left-Ge.width/2,lr=Le-Ge.top-Ge.height/2;Ke={x:Ae-(Ae-We.x)*tt,y:lr-(lr-We.y)*tt}}else if(at){Ke={x:We.x*tt,y:We.y*tt};const Ge=Math.min(1,(He-Ie)/Math.max(.01,He-c));Ke={x:Ke.x*(1-Ge*.65),y:Ke.y*(1-Ge*.65)}}else Ke={x:We.x*tt,y:We.y*tt};return ge(Ke,Ie)}),Ie)})},[ge,c,z]),It=o.useCallback(()=>{Re(L*d)},[Re,L,d]),Ct=o.useCallback(()=>{const ue=Math.max(c,L/d);if(ue<=c+.001){ie();return}w(ue),X({x:0,y:0})},[c,ie,L,d]);o.useEffect(()=>{if(!e)return;const ue=pe=>{if(pe.key==="Escape"&&m){pe.preventDefault(),r();return}pe.key==="ArrowLeft"&&re?(pe.preventDefault(),he(H-1)):pe.key==="ArrowRight"&&re?(pe.preventDefault(),he(H+1)):pe.key==="+"||pe.key==="="?(pe.preventDefault(),Re(L*d)):pe.key==="-"||pe.key==="_"?(pe.preventDefault(),Ct()):pe.key==="0"&&(pe.preventDefault(),ie())};return window.addEventListener("keydown",ue),()=>window.removeEventListener("keydown",ue)},[Re,m,re,r,e,ie,H,L,he,Ct,d]);const Et=ue=>{ue.preventDefault();const pe=ue.deltaY>0?1/d:d;Re(L*pe,ue.clientX,ue.clientY)},le=ue=>{L<=c+.001||(ue.currentTarget.setPointerCapture(ue.pointerId),te(!0),I.current={pointerId:ue.pointerId,startX:ue.clientX,startY:ue.clientY,originX:W.x,originY:W.y})},Fe=ue=>{const pe=I.current;!pe||pe.pointerId!==ue.pointerId||X(ge({x:pe.originX+(ue.clientX-pe.startX),y:pe.originY+(ue.clientY-pe.startY)},L))},ze=ue=>{var pe;((pe=I.current)==null?void 0:pe.pointerId)===ue.pointerId&&(I.current=null,te(!1))},ft=ue=>{if(ue.stopPropagation(),L>c+.05){ie();return}Re(Math.min(z,3),ue.clientX,ue.clientY)},Ve=ue=>{if(ue.touches.length!==2)return;te(!0);const[pe,Le]=[ue.touches[0],ue.touches[1]],He=Math.hypot(pe.clientX-Le.clientX,pe.clientY-Le.clientY);E.current={distance:He,scale:L}},Mt=ue=>{if(ue.touches.length!==2||!E.current)return;ue.preventDefault();const[pe,Le]=[ue.touches[0],ue.touches[1]],He=Math.hypot(pe.clientX-Le.clientX,pe.clientY-Le.clientY),Ie=(pe.clientX+Le.clientX)/2,tt=(pe.clientY+Le.clientY)/2,at=E.current.scale*(He/Math.max(1,E.current.distance));Re(at,Ie,tt)},bt=()=>{E.current=null,te(!1)};if(!A||!O)return null;const rt=Q.enabled,Wt=Q.animate?`transform ${Nr}ms ${_d}`:"none";return ct.createPortal(t.jsxs("div",{className:"fixed inset-0",style:{zIndex:k},role:"dialog","aria-modal":"true","aria-label":h,children:[t.jsx("button",{type:"button","aria-label":"Cerrar",className:"absolute inset-0 border-0",style:{background:"color-mix(in srgb, var(--bg-sidebar, var(--primary)) 72%, transparent)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",opacity:N?1:0,transition:`opacity ${rt?Nr:St}ms ${At}`,cursor:"default",zIndex:0},onClick:()=>{u&&r()}}),t.jsx("div",{ref:oe,className:"absolute inset-0 flex items-center justify-center",style:{zIndex:1,padding:de?"4.5rem 3.5rem 6.5rem":"4.5rem 3.5rem 2.5rem",opacity:rt||N?1:0,transform:rt||N?"translateY(0) scale(1)":"translateY(10px) scale(0.96)",transition:rt?"none":`opacity ${St}ms ${At}, transform ${St}ms ${At}`},onClick:ue=>{ue.target===ue.currentTarget&&u&&r()},onWheel:Et,children:t.jsx("div",{className:"relative flex max-h-full max-w-full items-center justify-center will-change-transform",style:{transform:Q.enabled?`translate3d(${Q.dx}px, ${Q.dy}px, 0) scale(${Q.scale})`:void 0,transformOrigin:"center center",transition:Q.enabled?Wt:void 0},children:t.jsx("div",{className:"relative flex max-h-full max-w-full items-center justify-center will-change-transform",style:{opacity:Z.opacity,filter:Z.blur?`blur(${Z.blur}px)`:"blur(0px)",transform:`translate3d(${Z.x}px, 0, 0) scale(${Z.scale})`,transition:Z.animate?[`opacity ${Xa}ms ${Ka}`,`transform ${Xa}ms ${Ka}`,`filter ${Xa}ms ${Ka}`].join(", "):"none"},children:t.jsx("div",{ref:K,className:"pointer-events-auto relative max-h-full max-w-full touch-none select-none will-change-transform",style:{cursor:L>c+.001?"grab":"zoom-in",transform:`translate3d(${W.x}px, ${W.y}px, 0) scale(${L})`,transformOrigin:"center center",transition:se?"none":`transform 220ms ${Pd}`},onClick:ue=>ue.stopPropagation(),onDoubleClick:ft,onPointerDown:le,onPointerMove:Fe,onPointerUp:ze,onPointerCancel:ze,onTouchStart:Ve,onTouchMove:Mt,onTouchEnd:bt,children:t.jsx("img",{src:O.src,alt:O.alt||"",draggable:!1,className:"block max-h-[min(78vh,820px)] max-w-[min(86vw,1100px)] object-contain",style:{display:"block",borderRadius:Za,imageRendering:L>2.5?"pixelated":"auto"},onLoad:()=>{Dt()}},O.src+String(H))})})})}),t.jsxs("div",{className:"pointer-events-none absolute inset-0",style:{zIndex:2,opacity:N?1:0,transform:N?"translateY(0)":"translateY(-6px)",transition:`opacity ${rt?Nr:St}ms ${At}, transform ${rt?Nr:St}ms ${At}`},children:[t.jsxs("div",{className:"pointer-events-none absolute inset-x-0 top-0 flex items-center justify-between gap-3 px-4 pt-4",children:[t.jsx("div",{className:"pointer-events-auto flex items-center gap-2",children:b&&n.length>0?t.jsxs("span",{className:"rounded-full px-3 py-1.5 text-xs font-semibold tracking-wide",style:Ga,children:[H+1," / ",n.length]}):null}),t.jsxs("div",{className:"pointer-events-auto flex items-center gap-2",children:[f?t.jsxs(t.Fragment,{children:[t.jsx(kr,{label:"Alejar",onClick:Ct,disabled:L<=c+.001,children:t.jsx(q.HiMinus,{className:"h-5 w-5"})}),t.jsx(kr,{label:"Restablecer tamaño",onClick:ie,disabled:ut,children:t.jsx(q.HiArrowsPointingIn,{className:"h-5 w-5"})}),t.jsx(kr,{label:"Acercar",onClick:It,disabled:L>=z-.001,children:t.jsx(q.HiPlus,{className:"h-5 w-5"})})]}):null,t.jsx(kr,{label:"Cerrar",onClick:r,children:t.jsx(q.HiXMark,{className:"h-5 w-5"})})]})]}),re?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"pointer-events-auto absolute left-3 top-1/2",style:{opacity:N?1:0,transform:N?"translate(0, -50%)":"translate(-8px, -50%)",transition:`opacity ${St}ms ${At}, transform ${St}ms ${At}`},children:t.jsx(kr,{label:"Anterior",size:"lg",onClick:()=>he(H-1),disabled:!g&&H<=0,children:t.jsx(q.HiChevronLeft,{className:"h-6 w-6"})})}),t.jsx("div",{className:"pointer-events-auto absolute right-3 top-1/2",style:{opacity:N?1:0,transform:N?"translate(0, -50%)":"translate(8px, -50%)",transition:`opacity ${St}ms ${At}, transform ${St}ms ${At}`},children:t.jsx(kr,{label:"Siguiente",size:"lg",onClick:()=>he(H+1),disabled:!g&&H>=n.length-1,children:t.jsx(q.HiChevronRight,{className:"h-6 w-6"})})})]}):null,de?t.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 flex justify-center px-4 pb-4 pt-8",style:{background:"linear-gradient(to top, color-mix(in srgb, var(--bg-sidebar, var(--primary)) 72%, transparent), transparent)"},children:t.jsx("div",{className:"pointer-events-auto flex max-w-full items-end gap-2.5 overflow-x-auto rounded-2xl px-2 py-2",style:{background:"color-mix(in srgb, var(--bg-card) 55%, transparent)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",scrollbarWidth:"thin"},role:"tablist","aria-label":"Miniaturas",children:n.map((ue,pe)=>{const Le=pe===H;return t.jsx("button",{type:"button",role:"tab","aria-selected":Le,"aria-label":ue.alt||`Imagen ${pe+1}`,onClick:He=>{He.stopPropagation(),he(pe)},className:"relative shrink-0 overflow-hidden transition-opacity",style:{width:56,height:42,borderRadius:Za,opacity:Le?1:.42,transition:`opacity 180ms ${At}`},children:t.jsx("img",{src:ue.src,alt:"",draggable:!1,className:"h-full w-full object-cover",style:{borderRadius:Za}})},`${ue.src}-${pe}`)})})}):null]})]}),document.body)}function Vd({children:e,className:r,style:n,maxZoom:a,minZoom:s,zoomStep:l,loop:i,showThumbnails:c}){const[d,u]=o.useState(!1),[m,b]=o.useState(0),[f,g]=o.useState([]),[v,k]=o.useState(null),h=o.useCallback(($,N,T)=>{g($),k(T??null),b(N),u(!0)},[]),A=o.useCallback($=>{Es($,h)},[h]);return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:`[&_img]:cursor-zoom-in ${r??""}`,style:n,onClick:A,children:e}),t.jsx(Ts,{open:d,onClose:()=>u(!1),index:m,onIndexChange:b,slides:f,originRect:v,maxZoom:a,minZoom:s,zoomStep:l,loop:i,showThumbnails:c})]})}function $s(e){if(e!==void 0)return typeof e=="number"?`${e}px`:e}function As(e,r){if(e.length!==r.length)return!1;const n=new Set(r);return e.every(a=>n.has(a))}function Qa(e){return e.normalize("NFD").replace(new RegExp("\\p{M}","gu"),"").toLowerCase()}function Yd(e,r){if(!r)return!0;const n=Qa(r);return Qa(e.label).includes(n)||!!(e.sublabel&&Qa(e.sublabel).includes(n))}function Xd({value:e,onChange:r,options:n,placeholder:a="Seleccionar…",disabled:s=!1,className:l="",style:i,height:c=40,padding:d="6px 10px",searchable:u=!0,minOptionsForSearch:m=6,maxVisibleValues:b=2,truncateSelectedValues:f=!0,emptyText:g="Sin resultados",clearLabel:v="Limpiar seleccion",pruneMissingValues:k=!0}){const[h,A]=o.useState(!1),[$,N]=o.useState(""),[T,x]=o.useState(0),[y,L]=o.useState(!1),[w,W]=o.useState({}),X=o.useRef(null),Z=o.useRef(null),D=o.useRef(null),Q=o.useRef(null),j=u&&n.length>=m,se=o.useMemo(()=>new Set(e),[e]),te=o.useMemo(()=>{const S=new Map;for(const H of n)S.set(H.value,H);return S},[n]),ee=o.useMemo(()=>{const S=[];for(const H of e){const O=te.get(H);O&&S.push(O)}return S},[te,e]),U=b==="all"?ee.length:b,J=ee.slice(0,U),ce=Math.max(0,ee.length-J.length),C=o.useMemo(()=>{const S=$.trim();return!j||!S?n:n.filter(H=>Yd(H,S))},[n,$,j]),_=o.useCallback(()=>{const S=X.current;if(!S)return;const H=S.getBoundingClientRect(),O=j?304:244,re=window.innerHeight-H.bottom,z=re<O&&H.top>re;W({position:"fixed",left:H.left,top:z?void 0:H.bottom+4,bottom:z?window.innerHeight-H.top+4:void 0,width:Math.max(H.width,240),zIndex:9999})},[j]),ae=o.useCallback(S=>{As(e,S)||r(S)},[r,e]),B=o.useCallback(S=>{const H=te.get(S);if(H!=null&&H.disabled)return;const O=se.has(S)?e.filter(re=>re!==S):[...e,S];ae(O)},[ae,te,e,se]),I=o.useCallback(()=>ae([]),[ae]),E=o.useCallback(()=>{A(!1),N(""),x(0)},[]);o.useEffect(()=>L(!0),[]);const oe=o.useMemo(()=>n.map(S=>S.value).join("\0"),[n]);o.useEffect(()=>{if(!k||e.length===0||n.length===0)return;const S=new Set(n.map(O=>O.value)),H=e.filter(O=>S.has(O));As(e,H)||r(H)},[oe]),o.useEffect(()=>{if(!h)return;function S(H){var re,z;const O=H.target;!((re=X.current)!=null&&re.contains(O))&&!((z=Z.current)!=null&&z.contains(O))&&E()}return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[E,h]),o.useEffect(()=>{h&&(x(0),_(),j&&setTimeout(()=>{var S;return(S=D.current)==null?void 0:S.focus()},0))},[h,j,_]),o.useEffect(()=>{if(h)return window.addEventListener("resize",_),window.addEventListener("scroll",_,!0),()=>{window.removeEventListener("resize",_),window.removeEventListener("scroll",_,!0)}},[h,_]),o.useEffect(()=>{if(C.length===0){x(0);return}x(S=>Math.min(S,C.length-1))},[C.length]),o.useEffect(()=>{if(T<0||!Q.current)return;const S=Q.current.children[T];S==null||S.scrollIntoView({block:"nearest"})},[T]);function K(S){if(!s){if(!h){(S.key==="Enter"||S.key===" "||S.key==="ArrowDown")&&(S.preventDefault(),A(!0));return}if(S.key==="Escape"){S.preventDefault(),E();return}if(S.key==="ArrowDown"){if(S.preventDefault(),C.length===0)return;x(H=>Math.min(H+1,C.length-1));return}if(S.key==="ArrowUp"){S.preventDefault(),x(H=>Math.max(H-1,0));return}if(S.key==="Enter"&&C[T]&&!C[T].disabled){S.preventDefault(),B(C[T].value);return}S.key==="Backspace"&&!$&&e.length&&(S.preventDefault(),ae(e.slice(0,-1)))}}const Y=t.jsxs("div",{ref:Z,className:"overflow-hidden rounded-xl shadow-xl",style:{...w,background:"var(--bg-card)",border:"1px solid var(--border)"},children:[j&&t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",style:{borderBottom:"1px solid var(--border)"},children:[t.jsx(q.HiMagnifyingGlass,{className:"h-3.5 w-3.5 flex-shrink-0",style:{color:"var(--text-muted)"}}),t.jsx("input",{ref:D,value:$,onChange:S=>{N(S.target.value),x(0)},onKeyDown:S=>{(S.key==="ArrowDown"||S.key==="ArrowUp"||S.key==="Enter"||S.key==="Escape")&&(S.stopPropagation(),K(S))},placeholder:"Buscar…",className:"min-w-0 flex-1 bg-transparent text-sm outline-none",style:{color:"var(--text-main)"}}),$&&t.jsx("button",{type:"button","aria-label":"Limpiar búsqueda",onMouseDown:S=>{S.preventDefault(),N(""),x(0)},children:t.jsx(q.HiXMark,{className:"h-3.5 w-3.5",style:{color:"var(--text-muted)"}})})]}),e.length>0&&t.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-2 text-xs",style:{borderBottom:"1px solid var(--border)",color:"var(--text-muted)"},children:[t.jsxs("span",{children:[ee.length," seleccionados",e.length>ee.length?` (${e.length-ee.length} no disponibles)`:""]}),t.jsx("button",{type:"button",onMouseDown:S=>{S.preventDefault(),I()},className:"font-semibold transition-colors hover:text-[var(--primary)]",children:v})]}),t.jsxs("ul",{ref:Q,role:"listbox","aria-multiselectable":"true",className:"overflow-y-auto",style:{maxHeight:j?220:200,scrollbarWidth:"thin",scrollbarColor:"var(--border) transparent",overscrollBehavior:"contain"},children:[C.map((S,H)=>{const O=H===T,re=se.has(S.value);return t.jsxs("li",{role:"option","aria-selected":re,onMouseDown:z=>{z.preventDefault(),!S.disabled&&B(S.value)},onMouseEnter:()=>!S.disabled&&x(H),className:"flex cursor-pointer items-center gap-2 px-3 py-2 text-sm transition-colors",style:{background:O?"var(--bg-hover)":re?"color-mix(in srgb, var(--primary) 6%, transparent)":"transparent",color:S.disabled?"var(--text-muted)":"var(--text-main)",cursor:S.disabled?"not-allowed":"pointer",opacity:S.disabled?.58:1},children:[t.jsx("span",{className:"flex h-4 w-4 flex-shrink-0 items-center justify-center rounded border",style:{borderColor:re?"var(--primary)":"var(--border)",background:re?"var(--primary)":"var(--bg-input)",color:"var(--primary-fg)"},children:re&&t.jsx(q.HiCheck,{className:"h-3 w-3"})}),S.color&&t.jsx("span",{className:"h-2.5 w-2.5 flex-shrink-0 rounded-full",style:{background:S.color}}),t.jsxs("span",{className:"flex min-w-0 flex-1 items-baseline gap-1 overflow-hidden",children:[t.jsx(Pt,{className:"min-w-0 flex-1",children:S.label}),S.sublabel&&t.jsx(Pt,{className:"min-w-0 flex-shrink",style:{color:"var(--text-muted)",fontSize:12},children:S.sublabel})]}),S.badge&&t.jsx("span",{className:"flex-shrink-0 text-xs",style:{color:"var(--text-muted)"},children:S.badge})]},S.value)}),C.length===0&&t.jsx("li",{className:"px-3 py-4 text-center text-sm",style:{color:"var(--text-muted)"},children:g})]})]});return t.jsxs("div",{ref:X,className:`relative ${l||"w-full"}`,style:i,onKeyDown:K,children:[t.jsxs("button",{type:"button",disabled:s,onClick:()=>{s||(h?E():A(!0))},className:"flex w-full items-center gap-2 rounded-lg text-left text-sm transition-colors focus:outline-none",style:{minHeight:$s(c),padding:$s(d),background:"var(--bg-input)",color:ee.length?"var(--text-main)":"var(--text-muted)",border:h?"1px solid var(--primary)":"1px solid var(--border)",opacity:s?.5:1,cursor:s?"not-allowed":"pointer"},"aria-haspopup":"listbox","aria-expanded":h,children:[t.jsx("span",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1.5 overflow-hidden",children:J.length?t.jsxs(t.Fragment,{children:[J.map(S=>t.jsxs("span",{className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 text-xs font-semibold ${f?"max-w-[160px]":"max-w-full whitespace-normal"}`,style:{background:"var(--bg-card)",borderColor:"var(--border)",color:"var(--text-main)"},children:[S.color&&t.jsx("span",{className:"h-1.5 w-1.5 flex-shrink-0 rounded-full",style:{background:S.color}}),f?t.jsx(Pt,{className:"min-w-0 flex-1",children:S.label}):t.jsx("span",{className:"break-words",children:S.label}),t.jsx("span",{role:"button",tabIndex:-1,"aria-label":`Quitar ${S.label}`,onMouseDown:H=>{H.preventDefault(),H.stopPropagation(),B(S.value)},className:"flex-shrink-0 rounded-full p-0.5 transition-colors hover:bg-black/10",style:{color:"var(--text-muted)"},children:t.jsx(q.HiXMark,{className:"h-3 w-3"})})]},S.value)),ce>0&&t.jsxs("span",{className:"inline-flex items-center rounded-md px-1.5 py-0.5 text-xs font-semibold",style:{background:"color-mix(in srgb, var(--primary) 10%, transparent)",color:"var(--primary)"},children:["+",ce]})]}):t.jsx("span",{className:"truncate",children:a})}),ee.length?t.jsx("span",{role:"button",tabIndex:-1,"aria-label":v,onMouseDown:S=>{S.preventDefault(),S.stopPropagation(),I()},className:"flex-shrink-0 rounded-full p-0.5 transition-colors hover:bg-black/10",style:{color:"var(--text-muted)"},children:t.jsx(q.HiXMark,{className:"h-3.5 w-3.5"})}):t.jsx(q.HiChevronDown,{className:"h-4 w-4 flex-shrink-0 transition-transform",style:{color:"var(--text-muted)",transform:h?"rotate(180deg)":"rotate(0deg)"}})]}),h&&y&&ct.createPortal(Y,document.body)]})}function Kd({inputMode:e="decimal",...r}){return t.jsx(Ya,{...r,type:"number",inputMode:e})}function Gd(e,r,n){const a=[],s=Math.max(2,e-n),l=Math.min(r-1,e+n);a.push(1),s>2&&a.push("...");for(let i=s;i<=l;i+=1)a.push(i);return l<r-1&&a.push("..."),r>1&&a.push(r),a}function Zd({page:e,totalPages:r,onPageChange:n,disabled:a=!1,siblingCount:s=1,className:l=""}){const i=Math.max(1,r),c=Math.min(Math.max(1,e),i),d=Gd(c,i,s);return t.jsxs("nav",{"aria-label":"Paginacion",className:`inline-flex items-center gap-1 ${l}`,children:[t.jsx(Ue,{variant:"icon",size:"xs","aria-label":"Pagina anterior",disabled:a||c<=1,onClick:()=>n(c-1),children:t.jsx(q.HiChevronLeft,{className:"h-4 w-4"})}),d.map((u,m)=>u==="..."?t.jsx("span",{className:"flex h-8 min-w-8 items-center justify-center text-xs font-semibold text-[var(--text-muted)]",children:"..."},`ellipsis-${m}`):t.jsx("button",{type:"button","aria-current":u===c?"page":void 0,disabled:a,onClick:()=>n(u),className:"flex h-8 min-w-8 items-center justify-center rounded-md border px-2 text-xs font-semibold transition-colors disabled:cursor-not-allowed disabled:opacity-50",style:{borderColor:u===c?"var(--primary)":"var(--border)",background:u===c?"var(--primary)":"var(--bg-card)",color:u===c?"var(--primary-fg)":"var(--text-secondary)"},children:u},u)),t.jsx(Ue,{variant:"icon",size:"xs","aria-label":"Pagina siguiente",disabled:a||c>=i,onClick:()=>n(c+1),children:t.jsx(q.HiChevronRight,{className:"h-4 w-4"})})]})}const Ls=[{value:"+1",label:"+1",sublabel:"Estados Unidos, Canada, Caribe"},{value:"+7",label:"+7",sublabel:"Rusia, Kazajistan"},{value:"+20",label:"+20",sublabel:"Egipto"},{value:"+27",label:"+27",sublabel:"Sudafrica"},{value:"+30",label:"+30",sublabel:"Grecia"},{value:"+31",label:"+31",sublabel:"Paises Bajos"},{value:"+32",label:"+32",sublabel:"Belgica"},{value:"+33",label:"+33",sublabel:"Francia"},{value:"+34",label:"+34",sublabel:"Espana"},{value:"+36",label:"+36",sublabel:"Hungria"},{value:"+39",label:"+39",sublabel:"Italia, Vaticano"},{value:"+40",label:"+40",sublabel:"Rumania"},{value:"+41",label:"+41",sublabel:"Suiza"},{value:"+43",label:"+43",sublabel:"Austria"},{value:"+44",label:"+44",sublabel:"Reino Unido"},{value:"+45",label:"+45",sublabel:"Dinamarca"},{value:"+46",label:"+46",sublabel:"Suecia"},{value:"+47",label:"+47",sublabel:"Noruega"},{value:"+48",label:"+48",sublabel:"Polonia"},{value:"+49",label:"+49",sublabel:"Alemania"},{value:"+51",label:"+51",sublabel:"Peru"},{value:"+52",label:"+52",sublabel:"Mexico"},{value:"+53",label:"+53",sublabel:"Cuba"},{value:"+54",label:"+54",sublabel:"Argentina"},{value:"+55",label:"+55",sublabel:"Brasil"},{value:"+56",label:"+56",sublabel:"Chile"},{value:"+57",label:"+57",sublabel:"Colombia"},{value:"+58",label:"+58",sublabel:"Venezuela"},{value:"+60",label:"+60",sublabel:"Malasia"},{value:"+61",label:"+61",sublabel:"Australia"},{value:"+62",label:"+62",sublabel:"Indonesia"},{value:"+63",label:"+63",sublabel:"Filipinas"},{value:"+64",label:"+64",sublabel:"Nueva Zelanda"},{value:"+65",label:"+65",sublabel:"Singapur"},{value:"+66",label:"+66",sublabel:"Tailandia"},{value:"+81",label:"+81",sublabel:"Japon"},{value:"+82",label:"+82",sublabel:"Corea del Sur"},{value:"+84",label:"+84",sublabel:"Vietnam"},{value:"+86",label:"+86",sublabel:"China"},{value:"+90",label:"+90",sublabel:"Turquia"},{value:"+91",label:"+91",sublabel:"India"},{value:"+92",label:"+92",sublabel:"Pakistan"},{value:"+93",label:"+93",sublabel:"Afganistan"},{value:"+94",label:"+94",sublabel:"Sri Lanka"},{value:"+95",label:"+95",sublabel:"Myanmar"},{value:"+98",label:"+98",sublabel:"Iran"},{value:"+211",label:"+211",sublabel:"Sudan del Sur"},{value:"+212",label:"+212",sublabel:"Marruecos, Sahara Occidental"},{value:"+213",label:"+213",sublabel:"Argelia"},{value:"+216",label:"+216",sublabel:"Tunez"},{value:"+218",label:"+218",sublabel:"Libia"},{value:"+220",label:"+220",sublabel:"Gambia"},{value:"+221",label:"+221",sublabel:"Senegal"},{value:"+222",label:"+222",sublabel:"Mauritania"},{value:"+223",label:"+223",sublabel:"Mali"},{value:"+224",label:"+224",sublabel:"Guinea"},{value:"+225",label:"+225",sublabel:"Costa de Marfil"},{value:"+226",label:"+226",sublabel:"Burkina Faso"},{value:"+227",label:"+227",sublabel:"Niger"},{value:"+228",label:"+228",sublabel:"Togo"},{value:"+229",label:"+229",sublabel:"Benin"},{value:"+230",label:"+230",sublabel:"Mauricio"},{value:"+231",label:"+231",sublabel:"Liberia"},{value:"+232",label:"+232",sublabel:"Sierra Leona"},{value:"+233",label:"+233",sublabel:"Ghana"},{value:"+234",label:"+234",sublabel:"Nigeria"},{value:"+235",label:"+235",sublabel:"Chad"},{value:"+236",label:"+236",sublabel:"Republica Centroafricana"},{value:"+237",label:"+237",sublabel:"Camerun"},{value:"+238",label:"+238",sublabel:"Cabo Verde"},{value:"+239",label:"+239",sublabel:"Santo Tome y Principe"},{value:"+240",label:"+240",sublabel:"Guinea Ecuatorial"},{value:"+241",label:"+241",sublabel:"Gabon"},{value:"+242",label:"+242",sublabel:"Republica del Congo"},{value:"+243",label:"+243",sublabel:"Republica Democratica del Congo"},{value:"+244",label:"+244",sublabel:"Angola"},{value:"+245",label:"+245",sublabel:"Guinea-Bisau"},{value:"+246",label:"+246",sublabel:"Territorio Britanico del Oceano Indico"},{value:"+248",label:"+248",sublabel:"Seychelles"},{value:"+249",label:"+249",sublabel:"Sudan"},{value:"+250",label:"+250",sublabel:"Ruanda"},{value:"+251",label:"+251",sublabel:"Etiopia"},{value:"+252",label:"+252",sublabel:"Somalia"},{value:"+253",label:"+253",sublabel:"Yibuti"},{value:"+254",label:"+254",sublabel:"Kenia"},{value:"+255",label:"+255",sublabel:"Tanzania"},{value:"+256",label:"+256",sublabel:"Uganda"},{value:"+257",label:"+257",sublabel:"Burundi"},{value:"+258",label:"+258",sublabel:"Mozambique"},{value:"+260",label:"+260",sublabel:"Zambia"},{value:"+261",label:"+261",sublabel:"Madagascar"},{value:"+262",label:"+262",sublabel:"Reunion, Mayotte"},{value:"+263",label:"+263",sublabel:"Zimbabue"},{value:"+264",label:"+264",sublabel:"Namibia"},{value:"+265",label:"+265",sublabel:"Malaui"},{value:"+266",label:"+266",sublabel:"Lesoto"},{value:"+267",label:"+267",sublabel:"Botsuana"},{value:"+268",label:"+268",sublabel:"Esuatini"},{value:"+269",label:"+269",sublabel:"Comoras"},{value:"+290",label:"+290",sublabel:"Santa Elena"},{value:"+291",label:"+291",sublabel:"Eritrea"},{value:"+297",label:"+297",sublabel:"Aruba"},{value:"+298",label:"+298",sublabel:"Islas Feroe"},{value:"+299",label:"+299",sublabel:"Groenlandia"},{value:"+350",label:"+350",sublabel:"Gibraltar"},{value:"+351",label:"+351",sublabel:"Portugal"},{value:"+352",label:"+352",sublabel:"Luxemburgo"},{value:"+353",label:"+353",sublabel:"Irlanda"},{value:"+354",label:"+354",sublabel:"Islandia"},{value:"+355",label:"+355",sublabel:"Albania"},{value:"+356",label:"+356",sublabel:"Malta"},{value:"+357",label:"+357",sublabel:"Chipre"},{value:"+358",label:"+358",sublabel:"Finlandia, Aland"},{value:"+359",label:"+359",sublabel:"Bulgaria"},{value:"+370",label:"+370",sublabel:"Lituania"},{value:"+371",label:"+371",sublabel:"Letonia"},{value:"+372",label:"+372",sublabel:"Estonia"},{value:"+373",label:"+373",sublabel:"Moldavia"},{value:"+374",label:"+374",sublabel:"Armenia"},{value:"+375",label:"+375",sublabel:"Bielorrusia"},{value:"+376",label:"+376",sublabel:"Andorra"},{value:"+377",label:"+377",sublabel:"Monaco"},{value:"+378",label:"+378",sublabel:"San Marino"},{value:"+380",label:"+380",sublabel:"Ucrania"},{value:"+381",label:"+381",sublabel:"Serbia"},{value:"+382",label:"+382",sublabel:"Montenegro"},{value:"+383",label:"+383",sublabel:"Kosovo"},{value:"+385",label:"+385",sublabel:"Croacia"},{value:"+386",label:"+386",sublabel:"Eslovenia"},{value:"+387",label:"+387",sublabel:"Bosnia y Herzegovina"},{value:"+389",label:"+389",sublabel:"Macedonia del Norte"},{value:"+420",label:"+420",sublabel:"Chequia"},{value:"+421",label:"+421",sublabel:"Eslovaquia"},{value:"+423",label:"+423",sublabel:"Liechtenstein"},{value:"+500",label:"+500",sublabel:"Islas Malvinas"},{value:"+501",label:"+501",sublabel:"Belice"},{value:"+502",label:"+502",sublabel:"Guatemala"},{value:"+503",label:"+503",sublabel:"El Salvador"},{value:"+504",label:"+504",sublabel:"Honduras"},{value:"+505",label:"+505",sublabel:"Nicaragua"},{value:"+506",label:"+506",sublabel:"Costa Rica"},{value:"+507",label:"+507",sublabel:"Panama"},{value:"+508",label:"+508",sublabel:"San Pedro y Miquelon"},{value:"+509",label:"+509",sublabel:"Haiti"},{value:"+590",label:"+590",sublabel:"Guadalupe, San Bartolome"},{value:"+591",label:"+591",sublabel:"Bolivia"},{value:"+592",label:"+592",sublabel:"Guyana"},{value:"+593",label:"+593",sublabel:"Ecuador"},{value:"+594",label:"+594",sublabel:"Guayana Francesa"},{value:"+595",label:"+595",sublabel:"Paraguay"},{value:"+596",label:"+596",sublabel:"Martinica"},{value:"+597",label:"+597",sublabel:"Surinam"},{value:"+598",label:"+598",sublabel:"Uruguay"},{value:"+599",label:"+599",sublabel:"Caribe Neerlandes, Curazao"},{value:"+670",label:"+670",sublabel:"Timor Oriental"},{value:"+672",label:"+672",sublabel:"Antartida, Isla Norfolk"},{value:"+673",label:"+673",sublabel:"Brunei"},{value:"+674",label:"+674",sublabel:"Nauru"},{value:"+675",label:"+675",sublabel:"Papua Nueva Guinea"},{value:"+676",label:"+676",sublabel:"Tonga"},{value:"+677",label:"+677",sublabel:"Islas Salomon"},{value:"+678",label:"+678",sublabel:"Vanuatu"},{value:"+679",label:"+679",sublabel:"Fiyi"},{value:"+680",label:"+680",sublabel:"Palaos"},{value:"+681",label:"+681",sublabel:"Wallis y Futuna"},{value:"+682",label:"+682",sublabel:"Islas Cook"},{value:"+683",label:"+683",sublabel:"Niue"},{value:"+685",label:"+685",sublabel:"Samoa"},{value:"+686",label:"+686",sublabel:"Kiribati"},{value:"+687",label:"+687",sublabel:"Nueva Caledonia"},{value:"+688",label:"+688",sublabel:"Tuvalu"},{value:"+689",label:"+689",sublabel:"Polinesia Francesa"},{value:"+690",label:"+690",sublabel:"Tokelau"},{value:"+691",label:"+691",sublabel:"Micronesia"},{value:"+692",label:"+692",sublabel:"Islas Marshall"},{value:"+850",label:"+850",sublabel:"Corea del Norte"},{value:"+852",label:"+852",sublabel:"Hong Kong"},{value:"+853",label:"+853",sublabel:"Macao"},{value:"+855",label:"+855",sublabel:"Camboya"},{value:"+856",label:"+856",sublabel:"Laos"},{value:"+880",label:"+880",sublabel:"Banglades"},{value:"+886",label:"+886",sublabel:"Taiwan"},{value:"+960",label:"+960",sublabel:"Maldivas"},{value:"+961",label:"+961",sublabel:"Libano"},{value:"+962",label:"+962",sublabel:"Jordania"},{value:"+963",label:"+963",sublabel:"Siria"},{value:"+964",label:"+964",sublabel:"Irak"},{value:"+965",label:"+965",sublabel:"Kuwait"},{value:"+966",label:"+966",sublabel:"Arabia Saudita"},{value:"+967",label:"+967",sublabel:"Yemen"},{value:"+968",label:"+968",sublabel:"Oman"},{value:"+970",label:"+970",sublabel:"Palestina"},{value:"+971",label:"+971",sublabel:"Emiratos Arabes Unidos"},{value:"+972",label:"+972",sublabel:"Israel"},{value:"+973",label:"+973",sublabel:"Barein"},{value:"+974",label:"+974",sublabel:"Catar"},{value:"+975",label:"+975",sublabel:"Butan"},{value:"+976",label:"+976",sublabel:"Mongolia"},{value:"+977",label:"+977",sublabel:"Nepal"},{value:"+992",label:"+992",sublabel:"Tayikistan"},{value:"+993",label:"+993",sublabel:"Turkmenistan"},{value:"+994",label:"+994",sublabel:"Azerbaiyan"},{value:"+995",label:"+995",sublabel:"Georgia"},{value:"+996",label:"+996",sublabel:"Kirguistan"},{value:"+998",label:"+998",sublabel:"Uzbekistan"}];function Ds(e){return e==null?"":String(e)}function On(e){return e?e.startsWith("+")?e:`+${e}`:"+1"}function Qd(e){return typeof e=="number"?`${e}px`:e}function Jd({autoComplete:e="tel",inputMode:r="tel",validate:n=!0,invalidMessage:a="Ingresa un telefono valido.",errorDisplay:s="tooltip",error:l,value:i,defaultValue:c,onChange:d,countryCode:u,defaultCountryCode:m="+1",onCountryCodeChange:b,allowedCountryCodes:f,countryCodeOptions:g,countryCodePlaceholder:v="Codigo",countryCodeClassName:k="",countryCodeWidth:h=84,onPhoneValueChange:A,label:$,containerClassName:N="",helperText:T,helperDisplay:x="inline",labelAction:y,className:L="",required:w,disabled:W,floatingLabel:X,showPasswordToggle:Z,nativeValidation:D,errorTooltipLabel:Q="Error de validacion",...j}){var z;const[se,te]=o.useState(()=>Ds(c)),[ee,U]=o.useState(()=>On(m)),J=o.useMemo(()=>{const de=g??Ls,he=f==null?void 0:f.map(On);return he!=null&&he.length?de.filter(ie=>he.includes(ie.value)):de},[f,g]),ce=((z=J[0])==null?void 0:z.value)??"+1",C=J.some(de=>de.value===On(u??ee))?On(u??ee):ce,_=i!==void 0?Ds(i):se,ae=`${C} ${_}`.trim(),B=n&&_.length>0&&!Ua(ae)?a:void 0,I=l??B,E=!!I,oe=E&&s!=="tooltip",K=E&&s!=="inline",Y=!!T&&x==="tooltip"&&!oe,S=E?"border-[var(--danger)] focus-within:border-[var(--danger)]":"border-[var(--border)] focus-within:border-[var(--primary)]",H=de=>{const he=de.currentTarget.value;i===void 0&&te(he),A==null||A(he,{countryCode:C,nationalNumber:he,fullNumber:`${C} ${he}`.trim()}),d==null||d(de)},O=de=>{u===void 0&&U(de),b==null||b(de),A==null||A(_,{countryCode:de,nationalNumber:_,fullNumber:`${de} ${_}`.trim()})},re=K?t.jsx(Yt,{as:"span",content:I,className:"absolute right-2.5 top-1/2 flex h-7 w-7 -translate-y-1/2 items-center justify-center rounded-md text-[var(--danger)] outline-none transition-colors hover:bg-[var(--danger-bg)] focus-visible:bg-[var(--danger-bg)]",children:t.jsx("span",{tabIndex:0,role:"img","aria-label":Q,className:"flex h-full w-full items-center justify-center outline-none",children:t.jsx(ks,{className:"h-[18px] w-[18px]"})})}):null;return t.jsxs("div",{className:`flex flex-col gap-2 ${N}`,children:[t.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-semibold uppercase text-[var(--text-muted)]",children:[t.jsx("span",{children:$}),w&&t.jsx("span",{className:"text-[var(--danger)]",children:"*"}),Y?t.jsx(xr,{content:T}):null,y&&t.jsx("span",{className:"ml-auto normal-case",children:y})]}),t.jsxs("span",{className:`flex h-10 min-w-0 items-center overflow-hidden rounded-lg border bg-[var(--bg-input)] transition-colors ${S}`,children:[t.jsx(ar,{value:C,onChange:O,options:J,placeholder:v,disabled:W,ariaLabel:"Codigo telefonico",triggerVariant:"ghost",showSelectedSublabel:!1,searchable:!0,minOptionsForSearch:0,dropdownMinWidth:300,className:`shrink-0 ${k}`,style:{width:Qd(h)},height:38,padding:"0 8px 0 10px"}),t.jsx("span",{className:"h-5 w-px shrink-0 bg-[var(--border)]"}),t.jsxs("span",{className:"relative min-w-0 flex-1 self-stretch",children:[t.jsx("input",{...j,value:i,defaultValue:c,type:"tel",inputMode:r,autoComplete:e,disabled:W,required:void 0,"aria-label":j["aria-label"]??(typeof $=="string"?$:void 0),"aria-invalid":E||j["aria-invalid"],className:`h-full w-full min-w-0 bg-transparent px-2 py-1.5 text-sm text-[var(--text-main)] outline-none placeholder:text-[var(--text-muted)] disabled:cursor-not-allowed disabled:opacity-60 ${K?"pr-10":""} ${L}`,onChange:H}),re]})]}),t.jsx(wr,{error:oe?I:void 0,helperText:T,helperDisplay:x})]})}function Rd({value:e,onChange:r,options:n,name:a,label:s,orientation:l="vertical",disabled:i=!1,className:c="",optionClassName:d=""}){return t.jsxs("fieldset",{className:`min-w-0 ${c}`,disabled:i,children:[s&&t.jsx("legend",{className:"mb-2 text-xs font-semibold uppercase text-[var(--text-muted)]",children:s}),t.jsx("div",{className:l==="horizontal"?"flex flex-wrap gap-2":"flex flex-col gap-2",children:n.map(u=>{const m=u.value===e,b=i||u.disabled;return t.jsxs("label",{className:`inline-flex min-w-0 items-start gap-2 rounded-lg border px-2.5 py-1.5 transition-colors ${b?"cursor-not-allowed opacity-60":"cursor-pointer hover:bg-[var(--bg-input)]"} ${d}`,style:{borderColor:m?"color-mix(in srgb, var(--primary) 48%, var(--border))":"var(--border)",background:m?"color-mix(in srgb, var(--primary) 8%, transparent)":"var(--bg-card)"},children:[t.jsxs("span",{className:"relative mt-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full border border-[var(--border)] bg-[var(--bg-input)]",children:[t.jsx("input",{type:"radio",name:a,value:u.value,checked:m,disabled:b,onChange:()=>r(u.value),className:"absolute inset-0 opacity-0"}),t.jsx("span",{className:`h-2 w-2 rounded-full transition ${m?"scale-100 opacity-100":"scale-50 opacity-0"}`,style:{background:"var(--primary)"}})]}),t.jsxs("span",{className:"min-w-0",children:[t.jsx("span",{className:"block text-sm font-medium leading-5 text-[var(--text-main)]",children:u.label}),u.description&&t.jsx("span",{className:"block text-xs leading-5 text-[var(--text-muted)]",children:u.description})]})]},u.value)})})]})}const eu=new Set(["table","thead","tbody","tfoot","tr","th","td","caption"]),Hn=(e,r,n)=>Math.min(n,Math.max(r,Math.round(e)||r)),Sr=12,Bn=8,Ja=(e,r,n)=>{const a=Pn(n),s=e.insertRow(r);for(let l=0;l<a;l+=1){const i=s.insertCell(-1);i.innerHTML="<br>"}return s.cells[0]??null},Is=(e,r)=>{const n=e.rows[r];if(!n)return null;const a=n.parentElement;if(!a)return null;if(a.tagName==="THEAD"){const l=e.tBodies[0]??e.createTBody();return l.rows.length>=Sr?null:Ja(l,0,e)}if(a.tagName==="TBODY"&&a.rows.length>=Sr)return null;const s=Array.from(a.rows).indexOf(n);return Ja(a,s+1,e)},tu=(e,r)=>{var s;const n=e.rows[r];if(!n)return!1;const a=n.parentElement;return(a==null?void 0:a.tagName)==="TBODY"&&a.rows.length<=1||(a==null?void 0:a.tagName)==="THEAD"&&((s=e.tBodies[0])==null?void 0:s.rows.length)===0&&e.rows.length<=1?!1:(n.remove(),!0)},Os=(e,r)=>Pn(e)>=Bn?!1:(e.querySelectorAll("tr").forEach(n=>{const a=n.closest("thead")!==null,s=document.createElement(a?"th":"td");a?s.textContent=`Columna ${n.cells.length+1}`:s.innerHTML="<br>";const l=n.cells[r];l!=null&&l.nextSibling?n.insertBefore(s,l.nextSibling):n.appendChild(s)}),!0),ru=(e,r)=>Pn(e)<=1?!1:(e.querySelectorAll("tr").forEach(n=>{var a;(a=n.cells[r])==null||a.remove()}),!0),Hs=e=>{e.querySelectorAll(".rich-table-row-active").forEach(r=>{r.classList.remove("rich-table-row-active")}),e.querySelectorAll(".rich-table-col-active").forEach(r=>{r.classList.remove("rich-table-col-active")})},Bs=(e,r,n)=>{Hs(e),r&&(r.classList.add("rich-table-row-active"),e.querySelectorAll("tr").forEach(a=>{var s;(s=a.cells[n])==null||s.classList.add("rich-table-col-active")}))},nu=(e,r,n)=>{const a=e.getBoundingClientRect();return{rowIndex:Array.from(e.rows).indexOf(r),colIndex:n.cellIndex,bar:{x:a.left+a.width/2,y:a.top-6}}},Fn=e=>{const r=e.cloneNode(!0);return r.querySelectorAll(".rich-table-ui").forEach(n=>n.remove()),r.querySelectorAll(".rich-table-wrap").forEach(n=>{const a=n.querySelector("table");a?n.replaceWith(a):n.remove()}),r.querySelectorAll("table").forEach(n=>{n.classList.add("rich-table")}),r.querySelectorAll(".rich-table-row-active, .rich-table-col-active").forEach(n=>{n.classList.remove("rich-table-row-active","rich-table-col-active")}),r.innerHTML},Fs=e=>{e.querySelectorAll(".rich-table-wrap").forEach(r=>{const n=r.querySelector("table");n&&r.replaceWith(n)}),e.querySelectorAll(".rich-table-ui").forEach(r=>r.remove()),e.querySelectorAll("table").forEach(r=>{r.classList.add("rich-table")})},au=(e,r,n,a,s)=>{switch(e){case"table-delete":return r.remove(),!0;case"table-row-add":{const l=Number.isFinite(n)?Is(r,n):Ra(r);return l&&_n(l,s,!0),!!l}case"table-row-del":return Number.isFinite(n)?tu(r,n):!1;case"table-col-add":return Number.isFinite(a)?Os(r,a):iu(r);case"table-col-del":return Number.isFinite(a)?ru(r,a):!1;default:return!1}},Pn=e=>{let r=0;return e.querySelectorAll("tr").forEach(n=>{r=Math.max(r,n.cells.length)}),r||1},ou=e=>{const r=e.tBodies[0]??e.createTBody();return Array.from(r.rows)},Ps=e=>(e==null?void 0:e.closest("table"))??null,_s=e=>{if(!e)return null;const r=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return(r==null?void 0:r.closest("td, th"))??null},su=e=>Array.from(e.querySelectorAll("th, td")),zs=(e,r)=>{if(e.closest("thead"))return!1;const n=e.closest("tbody")??r.tBodies[0];if(!n)return!1;const a=Array.from(n.rows),s=e.closest("tr");return!s||s!==a[a.length-1]?!1:e===s.cells[s.cells.length-1]},lu=e=>{const r=window.getSelection();if(!r||!r.isCollapsed||r.rangeCount===0)return!1;const n=r.getRangeAt(0);if(!e.contains(n.startContainer))return!1;const a=n.cloneRange();return a.selectNodeContents(e),a.setStart(n.endContainer,n.endOffset),a.toString().trim()===""},_n=(e,r,n=!0)=>{r==null||r.focus();const a=document.createRange();a.selectNodeContents(e),a.collapse(n);const s=window.getSelection();s==null||s.removeAllRanges(),s==null||s.addRange(a)},Ra=e=>{const r=ou(e);if(r.length>=Sr)return null;const n=r[r.length-1];if(!n){const a=e.tBodies[0]??e.createTBody();return Ja(a,0,e)}return Is(e,Array.from(e.rows).indexOf(n))},iu=e=>{const r=Pn(e)-1;return r<0?!1:Os(e,r)},eo=e=>{Fs(e)},cu=(e,r,n)=>{const a=Hn(e,1,Sr),s=Hn(r,1,Bn),l=n?`<thead><tr>${Array.from({length:s},(c,d)=>`<th>Columna ${d+1}</th>`).join("")}</tr></thead>`:"",i=Array.from({length:a},()=>`<tr>${Array.from({length:s},()=>"<td><br></td>").join("")}</tr>`).join("");return`<table class="rich-table">${l}<tbody>${i}</tbody></table><p><br></p>`},Ws=()=>'<button type="button" class="rich-img-del" data-action="delete-img" title="Eliminar imagen"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M9 2a1 1 0 0 0-.894.553L7.382 4H4a1 1 0 0 0 0 2v10a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V6a1 1 0 0 0 0-2h-3.382l-.724-1.447A1 1 0 0 0 11 2H9zm-1 6a1 1 0 1 1 2 0v4a1 1 0 1 1-2 0V8zm4 0a1 1 0 1 1 2 0v4a1 1 0 1 1-2 0V8z" clip-rule="evenodd"/></svg></button>',rn=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),js=e=>e.toLocaleLowerCase().replace(new RegExp("(^|[^\\p{L}\\p{N}])(\\p{L})","gu"),(r,n,a)=>`${n}${a.toLocaleUpperCase()}`),du=e=>e.replace(/[<>]/g,"").toLowerCase(),uu=new Set(["p","br","div","span","b","strong","i","em","u","s","strike","ul","ol","li","h1","h2","h3","h4","blockquote","a","img","hr","table","thead","tbody","tfoot","tr","th","td","caption"]),fu=/^[\s\u00a0]*([•●○■▪▫◆◇►▶➢❖✓✔\-–—*])[\s\u00a0]+/,bu=e=>{const r=e.indexOf("<!--StartFragment-->"),n=e.indexOf("<!--EndFragment-->");if(r!==-1&&n!==-1&&n>r)return e.slice(r+20,n);const a=e.match(/<body[^>]*>([\s\S]*)<\/body>/i);return a?a[1]:e},zn=(e,r)=>r.test(e),mu=e=>zn(e,/font-weight\s*:\s*(bold|[6-9]00)/i),pu=e=>zn(e,/font-style\s*:\s*italic/i),hu=e=>zn(e,/text-decoration(?:-line)?\s*:[^;]*underline/i),gu=e=>zn(e,/text-decoration(?:-line)?\s*:[^;]*(line-through|linethrough)/i),Wn=(e,r)=>{var a;if(!e.childNodes.length||e.childNodes.length===1&&((a=e.firstChild)==null?void 0:a.nodeType)===Node.ELEMENT_NODE&&e.firstChild.tagName.toLowerCase()===r)return;const n=e.ownerDocument.createElement(r);for(;e.firstChild;)n.appendChild(e.firstChild);e.appendChild(n)},jn=e=>{const r=e.parentNode;if(!r){e.remove();return}for(;e.firstChild;)r.insertBefore(e.firstChild,e);r.removeChild(e)},vu=e=>{const r=e.getAttribute("class")??"",n=e.getAttribute("style")??"";return/mso-list/i.test(n)||/MsoListParagraph/i.test(r)||/MsoList/i.test(r)},qs=e=>{const r=e.getAttribute("style")??"",n=e.textContent??"";return/mso-level-number-format\s*:\s*(decimal|arabic|roman|alpha)/i.test(r)||/^\s*\d+[.)]\s/.test(n)||/^\s*[a-zA-Z][.)]\s/.test(n)?"ol":"ul"},yu=e=>{const n=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT).nextNode();if(!n||!n.textContent)return;const a=n.textContent.replace(fu,"").replace(/^\s*\d+[.)]\s+/,"").replace(/^\s*[a-zA-Z][.)]\s+/,"");a!==n.textContent&&(n.textContent=a)},xu=e=>{const r=Array.from(e.querySelectorAll("span, font, p, div, li, h1, h2, h3, h4"));r.sort((n,a)=>a.querySelectorAll("*").length-n.querySelectorAll("*").length),r.forEach(n=>{const a=n.getAttribute("style")??"";a&&(mu(a)&&Wn(n,"strong"),pu(a)&&Wn(n,"em"),hu(a)&&Wn(n,"u"),gu(a)&&Wn(n,"s"))})},wu=e=>{const r=Array.from(e.querySelectorAll("p, div")).filter(vu);if(!r.length)return;let n=0;for(;n<r.length;){const a=r[n],s=qs(a),l=[a];let i=n+1;for(;i<r.length;){const u=r[i];if(qs(u)!==s)break;let m=l[l.length-1].nextSibling;for(;m&&m.nodeType===Node.TEXT_NODE&&!(m.textContent??"").trim();)m=m.nextSibling;if(m!==u)break;l.push(u),i++}const c=a.parentNode;if(!c){n=i;continue}const d=a.ownerDocument.createElement(s);c.insertBefore(d,a),l.forEach(u=>{yu(u);const m=u.ownerDocument.createElement("li");for(;u.firstChild;)m.appendChild(u.firstChild);d.appendChild(m),u.remove()}),n=i}},Nu=e=>e==="h1"?"h2":e==="h4"||e==="h5"||e==="h6"?"h3":e==="div"?"p":e,ku=e=>{const r=bu(e.replace(/<!--\[if[\s\S]*?<!\[endif\]-->/gi,"").replace(/<xml[\s\S]*?<\/xml>/gi,"").replace(/<style[\s\S]*?<\/style>/gi,"").replace(/<\/?o:[^>]*>/gi,"").replace(/<\/?w:[^>]*>/gi,"").replace(/<\/?m:[^>]*>/gi,"")),s=new DOMParser().parseFromString(`<!DOCTYPE html><html><body>${r}</body></html>`,"text/html").body;s.querySelectorAll("script, style, meta, link, xml, title, head, iframe, object, embed, form, input, button, textarea, select, noscript").forEach(i=>i.remove()),xu(s),wu(s);const l=i=>{const c=Array.from(i.childNodes);if(i.nodeType===Node.ELEMENT_NODE){const d=i,u=d.tagName.toLowerCase();if(u==="html"||u==="body"){c.forEach(l);return}if(u==="font"){jn(d),c.forEach(l);return}if(!uu.has(u)){jn(d),c.forEach(l);return}if(u==="div"){const b=d.getAttribute("class")??"";if(/rich-table-wrap/.test(b)){Array.from(d.attributes).forEach(f=>{f.name.toLowerCase()!=="class"&&d.removeAttribute(f.name)}),d.className="rich-table-wrap",c.forEach(l);return}}const m=Nu(u);if(m!==u){const b=d.ownerDocument.createElement(m);for(;d.firstChild;)b.appendChild(d.firstChild);d.replaceWith(b),l(b);return}if(eu.has(u)){Array.from(d.attributes).forEach(b=>{const f=b.name.toLowerCase();if(u==="td"||u==="th"){["colspan","rowspan"].includes(f)||d.removeAttribute(b.name);return}d.removeAttribute(b.name)}),u==="table"&&d.classList.add("rich-table"),c.forEach(l);return}if(Array.from(d.attributes).forEach(b=>{const f=b.name.toLowerCase(),g=b.value;if(f.startsWith("on")||f==="style"||f==="class"){d.removeAttribute(b.name);return}if(f==="lang"||f.startsWith("data-")||f.startsWith("mso-")){d.removeAttribute(b.name);return}if((f==="href"||f==="src")&&/^\s*javascript:/i.test(g)){d.removeAttribute(b.name);return}u!=="a"&&u!=="img"&&f!=="href"&&f!=="src"&&f!=="alt"&&(["href","src","alt","target","rel"].includes(f)||d.removeAttribute(b.name))}),u==="a"){const b=d.getAttribute("href");if(!b||/^\s*#/.test(b)&&b.length<2){jn(d),c.forEach(l);return}d.setAttribute("target","_blank"),d.setAttribute("rel","noopener noreferrer"),d.classList.add("rich-link")}if(u==="img"){const b=d.getAttribute("src")??"";if(!b||/^\s*javascript:/i.test(b)||/^file:/i.test(b)||/scheme\s*=\s*["']?file/i.test(b)){d.remove();return}d.classList.add("rich-img"),Array.from(d.attributes).forEach(f=>{["src","alt","class"].includes(f.name.toLowerCase())||d.removeAttribute(f.name)})}if(u==="span"){jn(d),c.forEach(l);return}}c.forEach(l)};return l(s),s.querySelectorAll("p, h2, h3, li").forEach(i=>{const c=(i.textContent??"").replace(/[\u00a0\s]+/g,"").trim(),d=i.querySelector("img, hr"),u=!c&&!d&&Array.from(i.childNodes).every(m=>m.nodeType===Node.TEXT_NODE||m.nodeType===Node.ELEMENT_NODE&&m.tagName.toLowerCase()==="br");(!c&&!d||u)&&i.remove()}),s.querySelectorAll("strong, b, em, i, u, s").forEach(i=>{let c=i.nextSibling;for(;c&&c.nodeType===Node.TEXT_NODE&&!(c.textContent??"").trim();)c=c.nextSibling;if(c&&c.nodeType===Node.ELEMENT_NODE&&c.tagName===i.tagName){const d=c;for(;d.firstChild;)i.appendChild(d.firstChild);d.remove()}}),s.innerHTML.replace(/<!--[\s\S]*?-->/g,"").replace(/&nbsp;/gi," ").replace(/(<br\s*\/?>\s*){3,}/gi,"<br><br>").replace(/<p>(?:\s|<br\s*\/?>)*<\/p>/gi,"").trim()},to=e=>rn(e).replace(/\r\n?/g,`
25
+ `).split(/\n{2,}/).map(r=>`<p>${r.replace(/\n/g,"<br>")||"<br>"}</p>`).join(""),Su=e=>new RegExp("\\p{L}","u").test(e),ro=(e,r)=>{const n=e.trim();return!n||!Su(n)?!1:r==="uppercase"?n===n.toLocaleUpperCase():r==="lowercase"?n===n.toLocaleLowerCase():n===js(n)},Us=e=>{const r=a=>{var s,l;if(!a.closest(".rich-img-wrap")){const i=document.createElement("span");i.className="rich-img-wrap",i.contentEditable="false",(s=a.parentNode)==null||s.insertBefore(i,a),i.appendChild(a),i.insertAdjacentHTML("beforeend",Ws())}(l=a.closest(".rich-img-wrap"))==null||l.classList.add("rich-img-broken")};e.querySelectorAll("img").forEach(a=>{if(!a.complete||a.naturalWidth===0){a.addEventListener("error",()=>r(a),{once:!0}),a.addEventListener("load",()=>{a.naturalWidth===0&&r(a)},{once:!0});const s=a.src;a.src="",a.src=s}});const n=a=>{const s=a.target;s.tagName==="IMG"&&r(s)};return e.addEventListener("error",n,!0),()=>e.removeEventListener("error",n,!0)};function Vs({value:e,onChange:r,placeholder:n="Escribe algo...",minHeight:a="80px",instanceId:s}){const l=o.useId(),i=s||l,c=o.useCallback(()=>document,[]),d=o.useRef(null),u=o.useRef(null),m=o.useRef(new Map),b=o.useRef(null),f=o.useRef(!1),g=o.useRef(e??""),v=o.useRef(r),k=o.useRef(()=>{}),h=o.useRef(!1),[A,$]=o.useState(()=>!e||e.trim()===""),[N,T]=o.useState(new Set),[x,y]=o.useState(null),[L,w]=o.useState(""),[W,X]=o.useState(""),[Z,D]=o.useState(""),[Q,j]=o.useState(""),[se,te]=o.useState(3),[ee,U]=o.useState(3),[J,ce]=o.useState(!0),[C,_]=o.useState(!1),[ae,B]=o.useState(null),[I,E]=o.useState(null),oe=o.useRef(null),K=o.useRef(!1),Y=o.useRef(null),S=o.useCallback(()=>f.current?u.current:d.current,[]);o.useEffect(()=>{v.current=r},[r]);const H=o.useCallback(()=>{const F=window.getSelection(),G=S();if(!F||!G||F.rangeCount===0||F.isCollapsed)return"";const fe=F.getRangeAt(0);return!G.contains(fe.startContainer)||!G.contains(fe.endContainer)?"":F.toString()},[S]);o.useEffect(()=>{const F=e??"";if(h.current&&F===g.current){h.current=!1,$(!F||F.trim()==="");return}h.current=!1,g.current=F;const G=[d.current,u.current].filter(be=>!!be);G.forEach(be=>{be.innerHTML!==F&&(be.innerHTML=F)}),$(!F||F.trim()===""),G.forEach(be=>eo(be));const fe=G.map(be=>Us(be));return()=>fe.forEach(be=>be())},[e]),o.useEffect(()=>{var be,Te;f.current=C;let F,G=0,fe;if(C){const ye=d.current;ye&&(g.current=Fn(ye));const Be=()=>{var Ye;const De=u.current;if(!De){G=requestAnimationFrame(Be);return}De.innerHTML!==g.current&&(De.innerHTML=g.current),F=Us(De),eo(De),$(((Ye=De.textContent)==null?void 0:Ye.trim())===""),fe=setTimeout(()=>De.focus(),60)};G=requestAnimationFrame(Be)}else{const ye=u.current,Be=d.current,De=ye?Fn(ye):g.current,Ye=g.current;g.current=De,Be&&Be.innerHTML!==De&&(Be.innerHTML=De),De!==Ye&&v.current(De),$(((Te=(be=ye??Be)==null?void 0:be.textContent)==null?void 0:Te.trim())==="")}return()=>{G&&cancelAnimationFrame(G),fe&&clearTimeout(fe),F==null||F()}},[C]);const O=o.useCallback(()=>{const F=["bold","italic","underline","strikeThrough","insertUnorderedList","insertOrderedList","justifyLeft","justifyCenter","justifyRight","justifyFull"],G=new Set;F.forEach(be=>{try{c().queryCommandState(be)&&G.add(be)}catch{return}});try{const be=du(c().queryCommandValue("formatBlock"));be&&G.add(`formatBlock:${be}`)}catch{}const fe=H();ro(fe,"uppercase")&&G.add("__upper"),ro(fe,"lowercase")&&G.add("__lower"),ro(fe,"capitalize")&&G.add("__cap"),T(G)},[H,c]),re=()=>{var G;const F=S();F&&(g.current=Fn(F),h.current=!0,v.current(g.current),$(((G=F.textContent)==null?void 0:G.trim())===""))};k.current=re;const z=o.useCallback(()=>{Y.current&&(clearTimeout(Y.current),Y.current=null),oe.current&&(Hs(oe.current),oe.current=null),K.current=!1,B(null),E(null)},[]),de=o.useCallback(()=>{Y.current&&(clearTimeout(Y.current),Y.current=null)},[]),he=o.useCallback(()=>{de(),Y.current=setTimeout(()=>{K.current||z()},280)},[de,z]);o.useEffect(()=>()=>{Y.current&&clearTimeout(Y.current)},[]);const ie=o.useCallback(F=>{const G=oe.current;if(!G||!G.isConnected){z();return}const fe=(ae==null?void 0:ae.rowIndex)??(I==null?void 0:I.rowIndex)??-1,be=(ae==null?void 0:ae.colIndex)??(I==null?void 0:I.colIndex)??-1;au(F,G,fe,be,S()),z(),k.current(),O()},[S,z,O,I,ae]),ge=o.useCallback(F=>{if(I)return;const G=F.currentTarget,fe=F.target;if(fe.closest(".rich-table-action-bar, .rich-table-context-menu")){de();return}const be=fe.closest("td, th");if(!be||!G.contains(be)){he();return}const Te=be.closest("tr"),ye=be.closest("table");if(!Te||!ye||!G.contains(ye)){he();return}de(),ye.classList.add("rich-table"),oe.current=ye,Bs(ye,Te,be.cellIndex),B(nu(ye,Te,be))},[de,he,I]),Me=o.useCallback(F=>{const G=F.relatedTarget;if(G instanceof Element&&(G.closest(".rich-table-action-bar")||G.closest(".rich-table-context-menu"))){de();return}he()},[de,he]),$e=o.useCallback(F=>{const G=F.currentTarget,be=F.target.closest("td, th");if(!be||!G.contains(be))return;const Te=be.closest("tr"),ye=be.closest("table");if(!Te||!ye||!G.contains(ye))return;F.preventDefault(),ye.classList.add("rich-table"),oe.current=ye;const Be=Array.from(ye.rows).indexOf(Te),De=be.cellIndex;Bs(ye,Te,De),B(null),E({x:F.clientX,y:F.clientY,rowIndex:Be,colIndex:De})},[]);o.useEffect(()=>{if(!ae&&!I)return;const F=()=>he();return window.addEventListener("scroll",F,!0),window.addEventListener("resize",F),()=>{window.removeEventListener("scroll",F,!0),window.removeEventListener("resize",F)}},[he,I,ae]),o.useEffect(()=>{if(!I)return;const F=G=>{const fe=G.target;fe instanceof Element&&fe.closest(".rich-table-context-menu")||E(null)};return window.addEventListener("mousedown",F),()=>window.removeEventListener("mousedown",F)},[I]);const Dt=F=>{if(!F){const G=d.current;G&&(g.current=Fn(G))}_(!F)},ut=(F,G)=>{var fe;(fe=S())==null||fe.focus(),c().execCommand(F,!1,G),re(),O()},Re=F=>{ut("formatBlock",F)},It=()=>{var F;(F=S())==null||F.focus(),c().execCommand("insertHTML",!1,"<hr><p><br></p>"),re(),O()},Ct=()=>{const F=window.getSelection();F&&F.rangeCount>0&&(b.current=F.getRangeAt(0).cloneRange())},Et=()=>{const F=window.getSelection();F&&b.current&&(F.removeAllRanges(),F.addRange(b.current))},le=F=>{if(Ct(),F==="link"){const G=window.getSelection();X(G&&!G.isCollapsed?G.toString():""),w("")}F==="image"&&(D(""),j("")),F==="table"&&(te(3),U(3),ce(!0)),y(F)},Fe=()=>{var be;if(!L.trim())return;Et(),(be=S())==null||be.focus();const F=window.getSelection(),fe=(F&&!F.isCollapsed?F.toString():"")||W.trim()||L.trim();c().execCommand("insertHTML",!1,`<a href="${rn(L.trim())}" target="_blank" rel="noopener noreferrer" class="rich-link">${rn(fe)}</a>`),re(),y(null)},ze=(F,G="")=>`<span class="rich-img-wrap" contenteditable="false"><img src="${rn(F)}" alt="${rn(G)}" class="rich-img" />${Ws()}</span>`,ft=()=>{var F;Z.trim()&&(Et(),(F=S())==null||F.focus(),c().execCommand("insertHTML",!1,ze(Z.trim(),Q.trim())),re(),y(null))},Ve=()=>{var F;Et(),(F=S())==null||F.focus(),c().execCommand("insertHTML",!1,cu(se,ee,J)),re(),y(null)},Mt=(F,G=1200,fe=1200,be=.72)=>new Promise((Te,ye)=>{const Be=new FileReader;Be.onerror=ye,Be.onload=De=>{var Ot;const Ye=(Ot=De.target)==null?void 0:Ot.result,Ze=new Image;Ze.onerror=ye,Ze.onload=()=>{let{width:ot,height:it}=Ze;if(ot>G||it>fe){const fn=Math.min(G/ot,fe/it);ot=Math.round(ot*fn),it=Math.round(it*fn)}const cr=document.createElement("canvas");cr.width=ot,cr.height=it;const qt=cr.getContext("2d");if(!qt){Te(Ye);return}qt.drawImage(Ze,0,0,ot,it),Te(cr.toDataURL("image/jpeg",be))},Ze.src=Ye},Be.readAsDataURL(F)}),bt=F=>{F.focus();const G=window.getSelection();if(!G||G.rangeCount===0||!F.contains(G.anchorNode)){const fe=document.createRange();fe.selectNodeContents(F),fe.collapse(!1),G==null||G.removeAllRanges(),G==null||G.addRange(fe)}},rt=o.useRef(()=>{});rt.current=F=>{const G=S();G&&(bt(G),c().execCommand("insertHTML",!1,F),eo(G),G.querySelectorAll("p").forEach(fe=>{!(fe.textContent??"").replace(/[\u00a0\s]+/g,"")&&!fe.querySelector("img, hr, table")&&fe.remove()}),re(),O())};const Wt=o.useRef(Mt);Wt.current=Mt;const ue=o.useRef(ze);ue.current=ze;const pe=o.useCallback(F=>{if(!F||m.current.has(F))return;const G=fe=>{const be=fe.clipboardData;if(!be)return;const Te=be.getData("text/html"),ye=be.getData("text/plain");if(Te||ye){fe.preventDefault(),fe.stopPropagation();try{const Ze=Te?ku(Te):to(ye);if(!Ze){ye&&rt.current(to(ye));return}rt.current(Ze)}catch{ye&&rt.current(to(ye))}return}const De=Array.from(be.items).find(Ze=>Ze.type.startsWith("image/"));if(!De)return;fe.preventDefault(),fe.stopPropagation();const Ye=De.getAsFile();Ye&&Wt.current(Ye).then(Ze=>{rt.current(ue.current(Ze,"imagen"))})};F.addEventListener("paste",G,!0),m.current.set(F,()=>{F.removeEventListener("paste",G,!0),m.current.delete(F)})},[]),Le=o.useCallback(F=>{var fe;const G=d.current;G&&G!==F&&((fe=m.current.get(G))==null||fe()),d.current=F,F&&pe(F)},[pe]),He=o.useCallback(F=>{var fe;const G=u.current;G&&G!==F&&((fe=m.current.get(G))==null||fe()),u.current=F,F&&pe(F)},[pe]);o.useEffect(()=>{const F=m.current;return()=>{F.forEach(G=>G()),F.clear()}},[]);const Ie=F=>{const G=window.getSelection(),fe=S();if(!G||!fe||G.rangeCount===0||G.isCollapsed)return;const be=G.getRangeAt(0);if(!fe.contains(be.startContainer)||!fe.contains(be.endContainer))return;const Te=be.toString();if(!Te)return;let ye=Te;F==="uppercase"?ye=Te.toLocaleUpperCase():F==="lowercase"?ye=Te.toLocaleLowerCase():ye=js(Te),be.deleteContents();const Be=document.createTextNode(ye);be.insertNode(Be);const De=document.createRange();De.setStart(Be,0),De.setEnd(Be,ye.length),G.removeAllRanges(),G.addRange(De),b.current=De.cloneRange(),re(),O()},tt=()=>{Ct(),O()},at=()=>{const F=S();F&&Fs(F),re(),O()},We=()=>{requestAnimationFrame(()=>{var F;(F=S())==null||F.focus()})},Ke=F=>{var G,fe;if((F.metaKey||F.ctrlKey)&&F.key==="Enter"){if(F.preventDefault(),F.stopPropagation(),F.repeat)return;(G=S())==null||G.focus(),c().execCommand("insertLineBreak",!1)||c().execCommand("insertHTML",!1,"<br>"),re(),O();return}if(F.key==="Tab"){const be=window.getSelection(),Te=_s((be==null?void 0:be.anchorNode)??null),ye=S(),Be=Ps(Te);if(Te&&Be&&(ye!=null&&ye.contains(Te))){F.preventDefault();const De=su(Be),Ye=De.indexOf(Te),Ze=Ye>=0?De[Ye+1]:null;if(Ze)_n(Ze,ye,!0);else if(zs(Te,Be)){const Ot=Ra(Be);Ot&&_n(Ot,ye,!0)}re(),O();return}F.preventDefault(),(fe=S())==null||fe.focus(),c().execCommand("insertText",!1,"    "),re(),O();return}if(F.key==="Enter"&&!F.shiftKey&&!(F.metaKey||F.ctrlKey)){const be=window.getSelection(),Te=_s((be==null?void 0:be.anchorNode)??null),ye=S(),Be=Ps(Te);if(Te&&Be&&(ye!=null&&ye.contains(Te))&&zs(Te,Be)&&lu(Te)){F.preventDefault();const De=Ra(Be);De&&_n(De,ye,!0),re(),O();return}}if(F.key==="Escape"){if(I){E(null);return}if(x){y(null);return}if(f.current){_(!1);return}}x||(F.ctrlKey||F.metaKey)&&(F.key==="b"&&(F.preventDefault(),ut("bold")),F.key==="i"&&(F.preventDefault(),ut("italic")),F.key==="u"&&(F.preventDefault(),ut("underline")),F.key==="k"&&(F.preventDefault(),le("link")))},Ge=()=>t.jsx("div",{className:"h-4 w-px flex-shrink-0 mx-1",style:{background:"var(--border)"}}),Ae=(F,G,fe,be,Te)=>{const ye=Te??(N.has(fe)||fe==="__link"&&x==="link"||fe==="__img"&&x==="image"||fe==="__table"&&x==="table");return t.jsx("button",{type:"button",title:G,tabIndex:-1,onFocus:We,onMouseDown:Be=>{Be.preventDefault(),be?be():ut(fe)},className:"flex h-7 w-7 items-center justify-center rounded text-xs font-bold transition-colors",style:{color:ye?"var(--primary)":"var(--text-secondary)",background:ye?"rgba(59,130,246,0.12)":"transparent"},children:F},fe)},lr=F=>{const G=F.target;if(G.closest("[data-action='delete-img']")){F.preventDefault();const fe=G.closest(".rich-img-wrap");fe&&(fe.remove(),re())}},ir=()=>{de(),K.current=!0},Or=()=>{K.current=!1,he()},Jt=(F,G,fe,be=!1)=>t.jsx("button",{type:"button",className:`rich-table-action-btn${be?" rich-table-action-btn--danger":""}`,title:F,"aria-label":F,onMouseDown:Te=>{Te.preventDefault(),Te.stopPropagation(),ie(fe)},children:G}),oa=()=>typeof document>"u"||!ae&&!I?null:ct.createPortal(t.jsxs(t.Fragment,{children:[ae&&!I&&t.jsxs("div",{className:"rich-table-action-bar",style:{left:ae.bar.x,top:ae.bar.y},onMouseEnter:ir,onMouseLeave:Or,children:[t.jsxs("span",{className:"rich-table-action-hint",children:["Fila ",ae.rowIndex+1," · Col ",ae.colIndex+1]}),t.jsxs("div",{className:"rich-table-action-group",children:[t.jsx("span",{className:"rich-table-action-label",children:"Fila"}),Jt("Añadir fila abajo","+","table-row-add"),Jt("Eliminar fila","−","table-row-del")]}),t.jsxs("div",{className:"rich-table-action-group",children:[t.jsx("span",{className:"rich-table-action-label",children:"Columna"}),Jt("Añadir columna a la derecha","+","table-col-add"),Jt("Eliminar columna","−","table-col-del")]}),Jt("Eliminar tabla","Eliminar","table-delete",!0)]}),I&&t.jsx("div",{className:"rich-table-context-menu",style:{left:I.x,top:I.y},onMouseDown:F=>F.stopPropagation(),children:[["Añadir fila abajo","table-row-add"],["Eliminar fila","table-row-del"],["Añadir columna a la derecha","table-col-add"],["Eliminar columna","table-col-del"],["Eliminar tabla","table-delete"]].map(([F,G])=>t.jsx("button",{type:"button",onMouseDown:fe=>{fe.preventDefault(),ie(G)},children:F},G))})]}),document.body),lt=F=>t.jsxs(t.Fragment,{children:[x==="link"&&t.jsxs("div",{className:"flex flex-shrink-0 flex-wrap items-center gap-2 border-t px-3 py-2",style:{borderColor:"var(--border)",background:F},children:[t.jsx("input",{autoFocus:!0,type:"url",value:L,onChange:G=>w(G.target.value),onKeyDown:G=>{G.key==="Enter"&&(G.preventDefault(),Fe()),G.key==="Escape"&&y(null)},placeholder:"https://...",className:"min-w-0 flex-1 rounded px-2 py-1 text-xs focus:outline-none",style:{background:"var(--bg-card)",border:"1px solid var(--border)",color:"var(--text-main)"}}),t.jsx("input",{type:"text",value:W,onChange:G=>X(G.target.value),onKeyDown:G=>{G.key==="Enter"&&(G.preventDefault(),Fe()),G.key==="Escape"&&y(null)},placeholder:"Texto (opcional)",className:"w-32 rounded px-2 py-1 text-xs focus:outline-none",style:{background:"var(--bg-card)",border:"1px solid var(--border)",color:"var(--text-main)"}}),t.jsx("button",{type:"button",onClick:Fe,className:"rounded px-2.5 py-1 text-xs font-semibold text-white",style:{background:"var(--primary)"},children:"OK"}),t.jsx("button",{type:"button",onClick:()=>y(null),className:"rounded px-2 py-1 text-xs",style:{color:"var(--text-muted)"},children:"x"})]}),x==="table"&&t.jsxs("div",{className:"flex flex-shrink-0 flex-wrap items-center gap-2 border-t px-3 py-2",style:{borderColor:"var(--border)",background:F},children:[t.jsxs("label",{className:"flex items-center gap-1 text-xs",style:{color:"var(--text-secondary)"},children:["Filas",t.jsx("input",{autoFocus:!0,type:"number",min:1,max:Sr,value:se,onChange:G=>te(Hn(Number(G.target.value),1,Sr)),onKeyDown:G=>{G.key==="Enter"&&(G.preventDefault(),Ve()),G.key==="Escape"&&y(null)},className:"w-14 rounded px-2 py-1 text-xs focus:outline-none",style:{background:"var(--bg-card)",border:"1px solid var(--border)",color:"var(--text-main)"}})]}),t.jsxs("label",{className:"flex items-center gap-1 text-xs",style:{color:"var(--text-secondary)"},children:["Columnas",t.jsx("input",{type:"number",min:1,max:Bn,value:ee,onChange:G=>U(Hn(Number(G.target.value),1,Bn)),onKeyDown:G=>{G.key==="Enter"&&(G.preventDefault(),Ve()),G.key==="Escape"&&y(null)},className:"w-14 rounded px-2 py-1 text-xs focus:outline-none",style:{background:"var(--bg-card)",border:"1px solid var(--border)",color:"var(--text-main)"}})]}),t.jsxs("label",{className:"flex items-center gap-1.5 text-xs",style:{color:"var(--text-secondary)"},children:[t.jsx("input",{type:"checkbox",checked:J,onChange:G=>ce(G.target.checked)}),"Encabezado"]}),t.jsx("button",{type:"button",onClick:Ve,className:"rounded px-2.5 py-1 text-xs font-semibold text-white",style:{background:"var(--primary)"},children:"OK"}),t.jsx("button",{type:"button",onClick:()=>y(null),className:"rounded px-2 py-1 text-xs",style:{color:"var(--text-muted)"},children:"x"})]}),x==="image"&&t.jsxs("div",{className:"flex flex-shrink-0 flex-wrap items-center gap-2 border-t px-3 py-2",style:{borderColor:"var(--border)",background:F},children:[t.jsx("input",{autoFocus:!0,type:"url",value:Z,onChange:G=>D(G.target.value),onKeyDown:G=>{G.key==="Enter"&&(G.preventDefault(),ft()),G.key==="Escape"&&y(null)},placeholder:"URL de la imagen...",className:"min-w-0 flex-1 rounded px-2 py-1 text-xs focus:outline-none",style:{background:"var(--bg-card)",border:"1px solid var(--border)",color:"var(--text-main)"}}),t.jsx("input",{type:"text",value:Q,onChange:G=>j(G.target.value),onKeyDown:G=>{G.key==="Enter"&&(G.preventDefault(),ft()),G.key==="Escape"&&y(null)},placeholder:"Texto alt",className:"w-28 rounded px-2 py-1 text-xs focus:outline-none",style:{background:"var(--bg-card)",border:"1px solid var(--border)",color:"var(--text-main)"}}),t.jsx("button",{type:"button",onClick:ft,className:"rounded px-2.5 py-1 text-xs font-semibold text-white",style:{background:"var(--primary)"},children:"OK"}),t.jsx("button",{type:"button",onClick:()=>y(null),className:"rounded px-2 py-1 text-xs",style:{color:"var(--text-muted)"},children:"x"})]})]}),jt=(F,G)=>t.jsxs("div",{className:"flex flex-shrink-0 flex-wrap items-center gap-0.5 border-t px-2 py-1",style:{borderColor:"var(--border)",background:G},children:[Ae(t.jsx(q.HiArrowUturnLeft,{className:"h-4 w-4"}),"Deshacer","undo"),Ae(t.jsx(q.HiArrowUturnRight,{className:"h-4 w-4"}),"Rehacer","redo"),Ge(),Ae(t.jsx("span",{style:{fontSize:"10px"},children:"P"}),"Parrafo","__paragraph",()=>Re("p"),N.has("formatBlock:p")||N.has("formatBlock:div")),Ae(t.jsx(q.HiH2,{className:"h-4 w-4"}),"Titulo 2","__h2",()=>Re("h2"),N.has("formatBlock:h2")),Ae(t.jsx(q.HiH3,{className:"h-4 w-4"}),"Titulo 3","__h3",()=>Re("h3"),N.has("formatBlock:h3")),Ae(t.jsx("span",{style:{fontSize:"13px",lineHeight:1},children:"“"}),"Cita","__quote",()=>Re("blockquote"),N.has("formatBlock:blockquote")),Ge(),Ae(t.jsx("b",{children:"B"}),"Negrita (Ctrl+B)","bold"),Ae(t.jsx("i",{children:"I"}),"Cursiva (Ctrl+I)","italic"),Ae(t.jsx("u",{children:"U"}),"Subrayado (Ctrl+U)","underline"),Ae(t.jsx("s",{children:"S"}),"Tachado","strikeThrough"),Ge(),Ae(t.jsx(q.HiListBullet,{className:"h-4 w-4"}),"Lista sin orden","insertUnorderedList"),Ae(t.jsx(q.HiNumberedList,{className:"h-4 w-4"}),"Lista numerada","insertOrderedList"),Ae(t.jsx(q.HiArrowTurnUpLeft,{className:"h-4 w-4"}),"Disminuir sangria","outdent"),Ae(t.jsx(q.HiArrowTurnDownRight,{className:"h-4 w-4"}),"Aumentar sangria","indent"),Ge(),Ae(t.jsx(q.HiBars3BottomLeft,{className:"h-4 w-4"}),"Alinear izquierda","justifyLeft"),Ae(t.jsx(q.HiBars3CenterLeft,{className:"h-4 w-4"}),"Centrar","justifyCenter"),Ae(t.jsx(q.HiBars3BottomRight,{className:"h-4 w-4"}),"Alinear derecha","justifyRight"),Ae(t.jsx(q.HiBars3,{className:"h-4 w-4"}),"Justificar","justifyFull"),Ge(),Ae(t.jsx("span",{style:{fontSize:"10px"},children:"AA"}),"Mayusculas","__upper",()=>Ie("uppercase")),Ae(t.jsx("span",{style:{fontSize:"10px"},children:"aa"}),"Minusculas","__lower",()=>Ie("lowercase")),Ae(t.jsx("span",{style:{fontSize:"10px"},children:"Aa"}),"Capitalizar","__cap",()=>Ie("capitalize")),Ge(),Ae(t.jsx(q.HiLink,{className:"h-4 w-4"}),"Insertar enlace (Ctrl+K)","__link",()=>le("link")),Ae(t.jsx(q.HiLinkSlash,{className:"h-4 w-4"}),"Quitar enlace","unlink"),Ae(t.jsx(q.HiPhoto,{className:"h-4 w-4"}),"Insertar imagen","__img",()=>le("image")),Ae(t.jsx(q.HiTableCells,{className:"h-4 w-4"}),"Insertar tabla","__table",()=>le("table")),Ae(t.jsx(q.HiMinus,{className:"h-4 w-4"}),"Insertar separador","__divider",It),Ge(),Ae(t.jsx(q.HiOutlinePaintBrush,{className:"h-4 w-4"}),"Limpiar formato","removeFormat"),Ae(t.jsx(q.HiNoSymbol,{className:"h-4 w-4"}),"Quitar bloque","__clearBlock",()=>Re("p")),Ge(),t.jsx("button",{type:"button",title:F?"Salir del modo de enfoque (Esc)":"Modo de enfoque",tabIndex:-1,onFocus:We,onMouseDown:fe=>{fe.preventDefault(),Dt(F)},className:"flex h-7 w-7 items-center justify-center rounded transition-colors",style:{color:"var(--text-secondary)"},children:F?t.jsx(q.HiArrowsPointingIn,{className:"h-4 w-4"}):t.jsx(q.HiArrowsPointingOut,{className:"h-4 w-4"})})]});return t.jsxs(t.Fragment,{children:[oa(),t.jsxs("div",{className:"overflow-hidden rounded-lg transition-all duration-150 ring-1 ring-transparent focus-within:ring-primary/30",style:{border:"1px solid var(--border)"},children:[t.jsx("div",{ref:Le,contentEditable:!0,suppressContentEditableWarning:!0,"data-bonsaif-rich-instance":i,onInput:at,onKeyDown:Ke,onKeyUp:tt,onSelect:tt,onMouseUp:tt,onMouseMove:ge,onMouseLeave:Me,onContextMenu:$e,onMouseDown:lr,"data-placeholder":n,className:`rich-editor px-3 py-2 text-sm focus:outline-none${A?" is-empty":""}`,style:{color:"var(--text-main)",background:"var(--bg-input)",minHeight:a,maxHeight:"320px",overflowY:"auto",lineHeight:"1.6"}}),lt("var(--bg-input)"),jt(!1,"var(--bg-input)")]}),t.jsxs(Oa,{open:C,onClose:()=>_(!1),title:"Modo de enfoque",subtitle:"Esc para salir",maxWidth:"920px",bodyClassName:"flex min-h-0 flex-col p-0",panelClassName:"h-[88vh]",backdropClassName:"bg-black/50 backdrop-blur-[2px]",children:[t.jsx("div",{ref:He,contentEditable:!0,suppressContentEditableWarning:!0,"data-bonsaif-rich-instance":i,onInput:at,onKeyDown:Ke,onKeyUp:tt,onSelect:tt,onMouseUp:tt,onMouseMove:ge,onMouseLeave:Me,onContextMenu:$e,onMouseDown:lr,"data-placeholder":n,className:`rich-editor min-h-0 flex-1 overflow-y-auto px-8 py-6 text-sm focus:outline-none${A?" is-empty":""}`,style:{color:"var(--text-main)",background:"var(--bg-card)",lineHeight:"1.75"}}),lt("var(--bg-input)"),jt(!0,"var(--bg-input)")]})]})}const Ys="[a-zA-Z0-9._@-]+",no=new RegExp(`@(${Ys})`,"g"),Cu=/[a-zA-Z0-9._@-]/,nn=new Set([" ",`
26
+ `," ","\r"," ","(","[","{",".",",",";",":","!","?","¿","¡",")","]","}",'"',"'","«","»","/","\\","|","-","—","–"]);function Xs(e,r){if(r<=0)return!0;const n=e[r-1]??"";return nn.has(n)}function Ks(e,r,n){var a;if(r<0||r>e.length)return null;for(let s=r-1;s>=0;s-=1){if(e[s]!=="@"){const c=e[s]??"";if(nn.has(c)||!Cu.test(c))return null;continue}if((a=n==null?void 0:n.isInsideExistingMention)!=null&&a.call(n,s)||!(n!=null&&n.isTriggerBoundary?n.isTriggerBoundary(s):Xs(e,s)))continue;const i=e.slice(s+1,r);return i.length>0&&!new RegExp(`^${Ys}$`).test(i)?null:{query:i,triggerIndex:s,caretIndex:r}}return null}function Gs(e,r){var a;const n=Cr(e,r);return n?!!((a=n.node.parentElement)!=null&&a.closest(".mention-chip")):!1}function Zs(e,r){if(r<=0)return!0;const n=Cr(e,r);if(!n){const s=co(e);return Xs(s,r)}if(n.offset>0){const s=n.node.data[n.offset-1]??"";return nn.has(s)}let a=n.node.previousSibling;for(;a;){if(a.nodeType===Node.TEXT_NODE){const s=a.textContent??"";if(s.length===0){a=a.previousSibling;continue}return nn.has(s[s.length-1]??"")}if(a.nodeType===Node.ELEMENT_NODE){const s=a;if(s.classList.contains("mention-chip")||s.tagName==="BR"||/^(P|DIV|LI|H[1-6]|BLOCKQUOTE)$/i.test(s.tagName))return!0;const l=s.textContent??"";if(l.length===0){a=a.previousSibling;continue}return nn.has(l[l.length-1]??"")}a=a.previousSibling}return!0}function ao(e,r){const n=co(e);return Ks(n,r,{isTriggerBoundary:a=>Zs(e,a),isInsideExistingMention:a=>Gs(e,a)})}function oo(e){return e.toLowerCase().trim()}function Qs(e){return e?e.replace(/<style[^>]*>[\s\S]*?<\/style>/gi," ").replace(/<script[^>]*>[\s\S]*?<\/script>/gi," ").replace(/<br\s*\/?>/gi,`
27
27
  `).replace(/<\/(p|div|li)>/gi,`
28
- `).replace(/<[^>]+>/g," ").replace(/&nbsp;/g," ").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#39;/g,"'").replace(/\s+/g," ").trim():""}function ro(e){if(!e)return[];const r=new Set,n=[],a=d=>{const u=to(d);!u||r.has(u)||(r.add(u),n.push(u))},s=/data-username\s*=\s*["']([^"']+)["']/gi;let l;for(;(l=s.exec(e))!==null;)a(l[1]??"");const i=Ys(e);Ra.lastIndex=0;let c;for(;(c=Ra.exec(i))!==null;)a(c[1]??"");return n}function Xs(e){const r=String(e.name??"").trim();return r||String(e.username??"").trim()||"usuario"}function yu(e,r){const n=ro(e);if(!n.length)return[];const a=new Map;r.forEach(i=>{i.username&&a.set(to(i.username),i)});const s=new Set,l=[];for(const i of n){const c=a.get(i);c&&(s.has(c.userId)||(s.add(c.userId),l.push({userId:c.userId,username:c.username,email:c.email??void 0,display:c.name??c.username})))}return l}function Ks(e){const r=new Set,n=[];for(const a of e)r.has(a.userId)||(r.add(a.userId),n.push(a));return n}function xu(e,r){return r?e.filter(n=>n.userId!==r):e}function Gs(e){return!e||!/@/.test(e)?e:e.replace(Ra,(r,n,a,s)=>{const l=s.slice(0,a),i=l.lastIndexOf("<"),c=l.lastIndexOf(">");return i>c?r:`<span class="mention-chip" contenteditable="false" data-username="${(n??"").toLowerCase()}">${r}</span>`})}const wu=new Set(["P","DIV","LI","H1","H2","H3","H4","H5","H6","BLOCKQUOTE"]);function Zs(e,r){return wu.has(e.tagName)&&e!==r}function no(e,r){let n="",a,s,l=!1;const i=(f,g)=>{if(l||!(r!=null&&r.domPoint))return;const{container:v,offset:k}=r.domPoint;v===f&&k===g&&(s=n.length,l=!0)},c=(f,g)=>(r==null?void 0:r.locatePlain)!==n.length?!1:(a={node:f,offset:g},!0),d=f=>(r==null?void 0:r.locatePlain)===n.length?(f==null?void 0:f.nodeType)===Node.TEXT_NODE?(a={node:f,offset:0},"matched"):"matched-at-newline":(n+=`
28
+ `).replace(/<[^>]+>/g," ").replace(/&nbsp;/g," ").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#39;/g,"'").replace(/\s+/g," ").trim():""}function so(e){if(!e)return[];const r=new Set,n=[],a=d=>{const u=oo(d);!u||r.has(u)||(r.add(u),n.push(u))},s=/data-username\s*=\s*["']([^"']+)["']/gi;let l;for(;(l=s.exec(e))!==null;)a(l[1]??"");const i=Qs(e);no.lastIndex=0;let c;for(;(c=no.exec(i))!==null;)a(c[1]??"");return n}function Js(e){const r=String(e.name??"").trim();return r||String(e.username??"").trim()||"usuario"}function Eu(e,r){const n=so(e);if(!n.length)return[];const a=new Map;r.forEach(i=>{i.username&&a.set(oo(i.username),i)});const s=new Set,l=[];for(const i of n){const c=a.get(i);c&&(s.has(c.userId)||(s.add(c.userId),l.push({userId:c.userId,username:c.username,email:c.email??void 0,display:c.name??c.username})))}return l}function Rs(e){const r=new Set,n=[];for(const a of e)r.has(a.userId)||(r.add(a.userId),n.push(a));return n}function Mu(e,r){return r?e.filter(n=>n.userId!==r):e}function el(e){return!e||!/@/.test(e)?e:e.replace(no,(r,n,a,s)=>{const l=s.slice(0,a),i=l.lastIndexOf("<"),c=l.lastIndexOf(">");if(i>c)return r;const d=(n??"").toLowerCase(),u=s[a+r.length]??"";return`<span class="mention-chip" contenteditable="false" data-username="${d}">${r}</span>${u===" "||u===" "?"":" "}`})}function lo(e){var r;(r=e.querySelectorAll)==null||r.call(e,".mention-chip").forEach(n=>{if(!(n instanceof HTMLElement))return;const a=n.ownerDocument,s=n.nextSibling;if((s==null?void 0:s.nodeType)===Node.TEXT_NODE){const l=s.textContent??"";if(l.startsWith(" ")||l.startsWith(" "))return;if(l.length>0){s.textContent=` ${l}`;return}}n.after(a.createTextNode(" "))})}const Tu=new Set(["P","DIV","LI","H1","H2","H3","H4","H5","H6","BLOCKQUOTE"]);function tl(e,r){return Tu.has(e.tagName)&&e!==r}function io(e,r){let n="",a,s,l=!1;const i=(f,g)=>{if(l||!(r!=null&&r.domPoint))return;const{container:v,offset:k}=r.domPoint;v===f&&k===g&&(s=n.length,l=!0)},c=(f,g)=>(r==null?void 0:r.locatePlain)!==n.length?!1:(a={node:f,offset:g},!0),d=f=>(r==null?void 0:r.locatePlain)===n.length?(f==null?void 0:f.nodeType)===Node.TEXT_NODE?(a={node:f,offset:0},"matched"):"matched-at-newline":(n+=`
29
29
  `,(r==null?void 0:r.locatePlain)===n.length?(f==null?void 0:f.nodeType)===Node.TEXT_NODE?(a={node:f,offset:0},"matched"):"matched-at-newline":!1),u=f=>{const g=f.data;for(let v=0;v<=g.length;v+=1){if(i(f,v),c(f,v))return!0;v<g.length&&(n+=g[v])}return!1},m=(f,g)=>{if(g&&n.length>0&&!n.endsWith(`
30
- `)&&d(f)==="matched")return!0;if(f.nodeType===Node.TEXT_NODE)return u(f);if(f.nodeType!==Node.ELEMENT_NODE)return!1;const v=f;if(v.tagName==="BR")return i(v,0),d(v.nextSibling??void 0)==="matched";const k=Array.from(f.childNodes);for(let h=0;h<k.length;h+=1){const C=k[h],M=h>0&&C.nodeType===Node.ELEMENT_NODE&&Zs(C,e);if(m(C,M))return!0}return!1},b=Array.from(e.childNodes);for(let f=0;f<b.length;f+=1){const g=b[f],v=f>0&&g.nodeType===Node.ELEMENT_NODE&&Zs(g,e);if(m(g,v))break}if((r==null?void 0:r.locatePlain)===n.length&&!a){const f=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT);let g=f.nextNode(),v=g;for(;v;)g=v,v=f.nextNode();g&&(a={node:g,offset:g.data.length})}return{plain:n,locate:a,domOffset:s}}function ao(e){return no(e).plain}function Cr(e,r){return r<0?null:no(e,{locatePlain:r}).locate??null}function _n(e,r,n){return e!==r&&!e.contains(r)?-1:no(e,{domPoint:{container:r,offset:n}}).domOffset??-1}function Qs(e,r){const{triggerIndex:n,caretIndex:a,username:s}=r;if(a<n)return null;const l=Cr(e,n),i=Cr(e,a);if(!l||!i)return null;const c=e.ownerDocument,d=c.createRange();d.setStart(l.node,l.offset),d.setEnd(i.node,i.offset),d.deleteContents();const u=Xs({name:r.display,username:s}),m=c.createElement("span");m.className="mention-chip",m.setAttribute("data-username",s.toLowerCase()),r.userId&&m.setAttribute("data-userid",String(r.userId)),m.contentEditable="false",m.textContent=u,m.title=`@${s}`;const b=c.createTextNode(" ");d.insertNode(b),d.insertNode(m);const f=c.defaultView,g=f==null?void 0:f.getSelection();if(g){const k=c.createRange();k.setStart(b,b.data.length),k.collapse(!0),g.removeAllRanges(),g.addRange(k)}const v=g!=null&&g.rangeCount?_n(e,g.getRangeAt(0).startContainer,g.getRangeAt(0).startOffset):n+u.length+1;return{caretPlainOffset:v>=0?v:n+u.length+1}}function Js(e,r){const n=e.ownerDocument,a=n.defaultView;if(!a)return;const s=a.getSelection();if(!s)return;const l=n.createRange(),i=Cr(e,r);i?(l.setStart(i.node,i.offset),l.collapse(!0)):(l.selectNodeContents(e),l.collapse(!1)),s.removeAllRanges(),s.addRange(l)}function zn(e){return e instanceof HTMLElement&&e.classList.contains("mention-chip")}function Rs(e,r){let n=e;for(;n&&n.nodeType===Node.TEXT_NODE&&!(n.textContent??"").replace(/\u00a0/g," ").trim();)n=r==="prev"?n.previousSibling:n.nextSibling;return n}function el(e){var s;const r=e.ownerDocument,n=(s=r.defaultView)==null?void 0:s.getSelection();if(!n)return;const a=r.createRange();a.selectNode(e),n.removeAllRanges(),n.addRange(a),e.classList.add("is-selected")}function Er(e=document){var r;(r=e.querySelectorAll)==null||r.call(e,".mention-chip.is-selected").forEach(n=>{n.classList.remove("is-selected")})}function Wn(e){var a;const r=(a=e.ownerDocument.defaultView)==null?void 0:a.getSelection();e.querySelectorAll(".mention-chip").forEach(s=>{let l=!1;if(r&&r.rangeCount>0)try{const i=r.getRangeAt(0);(!r.isCollapsed&&i.intersectsNode(s)||r.isCollapsed&&i.startContainer===s&&i.endContainer===s)&&(l=!0)}catch{l=!1}s.classList.toggle("is-selected",l)})}function tl(e){var s;const r=e.ownerDocument,n=(s=r.defaultView)==null?void 0:s.getSelection();if(!n)return;const a=r.createRange();a.selectNodeContents(e),n.removeAllRanges(),n.addRange(a),Wn(e)}function rl(e){const r=e.cloneContents();return r.querySelectorAll(".mention-chip").forEach(n=>n.remove()),(r.textContent??"").replace(/\u00a0/g," ").trim().length>0}function nl(e){var a;const r=(a=e.ownerDocument.defaultView)==null?void 0:a.getSelection();if(!r||r.isCollapsed||r.rangeCount===0)return!1;const n=r.getRangeAt(0);return e.contains(n.commonAncestorContainer)?(n.deleteContents(),Er(e),!0):!1}function jn(e){var m,b;const r=e.ownerDocument,n=e.parentNode;if(!n)return;const a=(f,g)=>{let v=f;for(;v&&v.nodeType===Node.TEXT_NODE&&(v.textContent??"")==="";){const k=v;v=v[g],k.remove()}return v},s=a(e.nextSibling,"nextSibling");if(s&&s.nodeType===Node.TEXT_NODE&&/^( |\u00a0)/.test(s.textContent??"")){const f=s;(f.data.length??0)<=1?f.remove():f.data=f.data.slice(1)}const l=a(e.previousSibling,"previousSibling"),i=n,c=Array.from(n.childNodes).indexOf(e);e.remove();const d=(m=r.defaultView)==null?void 0:m.getSelection();if(!d)return;const u=r.createRange();if(l)if(l.nodeType===Node.TEXT_NODE){const f=((b=l.textContent)==null?void 0:b.length)??0;u.setStart(l,f)}else u.setStartAfter(l);else i.childNodes[c]?u.setStart(i,c):(u.selectNodeContents(i),u.collapse(!1));u.collapse(!0),d.removeAllRanges(),d.addRange(u)}function al(e){var l;const r=(l=e.ownerDocument.defaultView)==null?void 0:l.getSelection();if(!r||!r.isCollapsed||r.rangeCount===0)return null;const n=r.getRangeAt(0);if(!e.contains(n.startContainer))return null;const{startContainer:a,startOffset:s}=n;if(a.nodeType===Node.TEXT_NODE){const i=a.textContent??"",c=Rs(a.previousSibling,"prev");return zn(c)&&(s===0||s===1&&(i.charAt(0)===" "||i.charAt(0)===" "))?c:null}if(a.nodeType===Node.ELEMENT_NODE){const i=a.childNodes;let c=s-1;for(;c>=0;){const d=i[c];if(zn(d))return d;if(d.nodeType===Node.TEXT_NODE&&!(d.textContent??"").replace(/\u00a0/g," ").trim()){c-=1;continue}break}}return null}function ol(e){var l;const r=(l=e.ownerDocument.defaultView)==null?void 0:l.getSelection();if(!r||!r.isCollapsed||r.rangeCount===0)return null;const n=r.getRangeAt(0);if(!e.contains(n.startContainer))return null;const{startContainer:a,startOffset:s}=n;if(a.nodeType===Node.TEXT_NODE){const i=a.textContent??"";if(s>=i.length){const c=Rs(a.nextSibling,"next");if(zn(c))return c}return null}if(a.nodeType===Node.ELEMENT_NODE){const i=a.childNodes;let c=s;for(;c<i.length;){const d=i[c];if(zn(d))return d;if(d.nodeType===Node.TEXT_NODE&&!(d.textContent??"").replace(/\u00a0/g," ").trim()){c+=1;continue}break}}return null}function oo(e){var s;const r=(s=e.ownerDocument.defaultView)==null?void 0:s.getSelection();if(!r||r.isCollapsed||r.rangeCount===0)return[];const n=r.getRangeAt(0);return e.contains(n.commonAncestorContainer)?Array.from(e.querySelectorAll(".mention-chip")).filter(l=>{try{return n.intersectsNode(l)}catch{return!1}}):[]}const so=280,qn=6,sl=260,Nu=new Set(["ArrowDown","ArrowUp","Enter","Tab","Escape"]),ll=4,ku={position:"relative"},Su={position:"fixed",zIndex:11050,minWidth:sl,overflowY:"auto",background:"var(--bg-card, var(--bonsaif-ui-surface, #fff))",border:"1px solid var(--border, var(--bonsaif-ui-border, #d0d7de))",borderRadius:10,boxShadow:"0 12px 32px rgba(0,0,0,0.18)",padding:4},il={padding:"10px 12px",fontSize:12,color:"var(--text-muted, #656d76)"};function Cu(e){return Array.from(document.querySelectorAll(`[data-bonsaif-rich-instance="${CSS.escape(e)}"]`))}function Eu(e,r){const n=Math.max(8,Math.min(e.left,window.innerWidth-sl-8)),a=r==null?void 0:r.getBoundingClientRect(),s=a?Math.min(window.innerHeight-8,a.bottom):window.innerHeight-8,l=a?Math.max(8,a.top):8,i=s-e.bottom-qn,c=e.top-l-qn;return i<Math.min(so,160)&&c>i?{left:n,bottom:window.innerHeight-e.top+qn,maxHeight:Math.max(120,Math.min(so,c))}:{left:n,top:e.bottom+qn,maxHeight:Math.max(120,Math.min(so,i))}}function cl({value:e,onChange:r,onSearchUsers:n,onMentionsChange:a,minHeight:s,placeholder:l,className:i,maxSuggestions:c=8,searchDebounceMs:d=140,highlightInEditor:u=!1,searchCacheKey:m=""}){const b=o.useId().replace(/:/g,""),f=o.useRef(null),g=o.useRef(null),v=o.useRef(new Map),k=o.useRef(n);k.current=n;const h=o.useRef(null),C=o.useRef(0),M=o.useRef([]),y=o.useRef(null),[x,w]=o.useState(null),[N,A]=o.useState([]),[T,U]=o.useState(0),[K,Z]=o.useState([]),[L,Q]=o.useState(!1),[z,se]=o.useState(!1);C.current=T,o.useEffect(()=>{se(!0)},[]);const re=(x==null?void 0:x.query)??null;o.useEffect(()=>{if(re===null){A([]);return}const D=re.trim(),$=`${m}|${D.toLowerCase()||"*"}`,oe=v.current.get($);if(oe){A(oe),Q(!1),U(0);return}const G=new AbortController;Q(!0);const X=window.setTimeout(()=>{(async()=>{try{const S=await k.current(D,{signal:G.signal,limit:c});if(G.signal.aborted)return;const O=Array.isArray(S)?S:[];v.current.set($,O),A(O),U(0)}catch{G.signal.aborted||A([])}finally{G.signal.aborted||Q(!1)}})()},d);return()=>{G.abort(),window.clearTimeout(X)}},[re,c,d,m]);const R=o.useRef(a);R.current=a,o.useEffect(()=>{var D;(D=R.current)==null||D.call(R,Ks(K))},[K]);const V=o.useCallback(()=>{const D=Cu(b);if(D.length===0)return null;const $=window.getSelection();if($!=null&&$.rangeCount){const G=$.getRangeAt(0).startContainer;for(const X of D)if(X.contains(G))return X}const oe=document.activeElement;for(const G of D)if(oe===G||oe&&G.contains(oe))return G;for(const G of D)if(G.closest('[role="dialog"]'))return G;return D[0]??null},[b]),B=o.useCallback(()=>{const D=V(),$=window.getSelection();if(!D||!$||$.rangeCount===0){w(null);return}const oe=$.getRangeAt(0);if(!D.contains(oe.startContainer)){w(null);return}const G=_n(D,oe.startContainer,oe.startOffset);if(G<0){w(null);return}const X=eo(D,G);if(!X){w(null);return}const S=oe.getBoundingClientRect(),O=S.width===0&&S.height===0?(()=>{const te=document.createRange();return te.selectNodeContents(oe.startContainer),te.collapse(!0),te.getBoundingClientRect()})():S;h.current={query:X.query,caretIndex:X.caretIndex,triggerIndex:X.triggerIndex};const I=Eu(O,D);w(te=>{const P={query:X.query,...I};return te&&te.query===P.query&&te.top===P.top&&te.bottom===P.bottom&&te.left===P.left&&te.maxHeight===P.maxHeight?te:P})},[V]),le=o.useCallback(D=>{r(D),B()},[r,B]);o.useEffect(()=>{const D=$=>{if(Nu.has($.key))return;const oe=V(),G=$.target;!oe||!G||!oe.contains(G)||B()};return document.addEventListener("keyup",D,!0),()=>document.removeEventListener("keyup",D,!0)},[V,B]);const j=o.useCallback(D=>{const $=V();if(!$)return;let oe=-1;const G=window.getSelection();if(G&&G.rangeCount>0){const te=G.getRangeAt(0);$.contains(te.startContainer)&&(oe=_n($,te.startContainer,te.startOffset))}if(oe<0&&h.current&&(oe=h.current.caretIndex),oe<0)return;const X=eo($,oe);if(!X)return;const S=Qs($,{triggerIndex:X.triggerIndex,caretIndex:oe,username:D.username,display:D.name,userId:D.userId});if(!S)return;$.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0}));const O={userId:D.userId,username:D.username,email:D.email??void 0,display:D.name??D.username};Z(te=>{const P=new Map(te.map(ce=>[ce.userId,ce]));return P.set(O.userId,O),Array.from(P.values())}),w(null),h.current=null;const I=S.caretPlainOffset;requestAnimationFrame(()=>{requestAnimationFrame(()=>{var ie,ge;const te=V();if(!te)return;te.focus(),Js(te,I);const P=window.getSelection(),ce=P==null?void 0:P.anchorNode,he=ce instanceof Element?ce.closest(".mention-chip"):(ie=ce==null?void 0:ce.parentElement)==null?void 0:ie.closest(".mention-chip");if(he!=null&&he.parentNode){const Te=document.createRange(),Le=he.nextSibling;Le&&Le.nodeType===Node.TEXT_NODE?Te.setStart(Le,((ge=Le.textContent)==null?void 0:ge.length)??0):Te.setStartAfter(he),Te.collapse(!0),P==null||P.removeAllRanges(),P==null||P.addRange(Te)}})})},[V]);o.useEffect(()=>{const D=new Set(ro(e).map($=>$.toLowerCase()));Z($=>{const oe=$.filter(G=>D.has(G.username.toLowerCase()));return oe.length===$.length?$:oe})},[e]),o.useEffect(()=>{if(!x)return;const D=$=>{const oe=$.target;if(!oe||f.current&&f.current.contains(oe)||g.current&&g.current.contains(oe))return;const G=V();G&&G.contains(oe)||w(null)};return document.addEventListener("mousedown",D),()=>{document.removeEventListener("mousedown",D)}},[x,V]);const W=o.useMemo(()=>N.slice(0,c),[N,c]);M.current=W,o.useEffect(()=>{if(!x)return;const D=$=>{const oe=V(),G=$.target;if(!oe||!G||!oe.contains(G))return;const X=M.current;if(!(X.length===0&&$.key!=="Escape"))if($.key==="ArrowDown")$.preventDefault(),$.stopPropagation(),U(S=>(S+1)%Math.max(X.length,1));else if($.key==="ArrowUp")$.preventDefault(),$.stopPropagation(),U(S=>(S-1+X.length)%Math.max(X.length,1));else if($.key==="Enter"||$.key==="Tab"){const S=X[C.current];S&&($.preventDefault(),$.stopPropagation(),j(S))}else $.key==="Escape"&&($.preventDefault(),$.stopPropagation(),w(null))};return document.addEventListener("keydown",D,!0),()=>document.removeEventListener("keydown",D,!0)},[V,j,x]),o.useEffect(()=>{const D=O=>{O.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0}))},$=O=>{const I=V(),te=O.target;if(!I||!te||!I.contains(te))return;if((O.metaKey||O.ctrlKey)&&O.key.toLowerCase()==="a"){O.preventDefault(),O.stopPropagation(),I.focus(),tl(I);return}if(O.key!=="Backspace"&&O.key!=="Delete")return;const P=window.getSelection();if(P&&!P.isCollapsed&&P.rangeCount>0){const ie=P.getRangeAt(0);if(I.contains(ie.commonAncestorContainer)&&oo(I).length>0&&rl(ie)){O.preventDefault(),O.stopPropagation(),nl(I)&&D(I);return}}const ce=oo(I);if(ce.length>0){O.preventDefault(),O.stopPropagation();for(const ie of ce)jn(ie);Er(I),D(I);return}if(O.key==="Backspace"){const ie=al(I);if(!ie)return;O.preventDefault(),O.stopPropagation(),jn(ie),Er(I),D(I);return}const he=ol(I);he&&(O.preventDefault(),O.stopPropagation(),jn(he),Er(I),D(I))},oe=O=>{const I=V();if(!I)return;const te=O.target;if(!(te instanceof Element)||!I.contains(te))return;const P=te.closest(".mention-chip");if(!(P instanceof HTMLElement)||!I.contains(P)){y.current=null,Er(I);return}O.shiftKey||O.button!==0||(y.current={chip:P,x:O.clientX,y:O.clientY})},G=O=>{const I=y.current;if(!I)return;const te=Math.abs(O.clientX-I.x),P=Math.abs(O.clientY-I.y);(te>ll||P>ll)&&(y.current=null)},X=O=>{var he;const I=V(),te=y.current;if(y.current=null,!I||!te)return;const P=O.target;if(!(P instanceof Element)||!I.contains(P)||!((he=P.closest(".mention-chip"))!=null&&he.isSameNode(te.chip)))return;const ce=window.getSelection();if(ce){if(!ce.isCollapsed){Wn(I);return}I.focus(),el(te.chip)}},S=()=>{const O=V();if(!O)return;const I=window.getSelection();!I||I.rangeCount===0||!I.anchorNode||!O.contains(I.anchorNode)||!I.focusNode||!O.contains(I.focusNode)||Wn(O)};return document.addEventListener("keydown",$,!0),document.addEventListener("mousedown",oe,!0),document.addEventListener("mousemove",G,!0),document.addEventListener("mouseup",X,!0),document.addEventListener("selectionchange",S),()=>{document.removeEventListener("keydown",$,!0),document.removeEventListener("mousedown",oe,!0),document.removeEventListener("mousemove",G,!0),document.removeEventListener("mouseup",X,!0),document.removeEventListener("selectionchange",S)}},[V]),o.useEffect(()=>{if(!x||!g.current)return;const D=g.current.querySelector(`[data-mention-index="${T}"]`);D==null||D.scrollIntoView({block:"nearest"})},[T,x]);const ae=u?Gs(e):e,H=x&&z?dt.createPortal(t.jsxs("ul",{ref:g,style:{...Su,left:x.left,top:x.top,bottom:x.bottom,maxHeight:x.maxHeight},role:"listbox","aria-label":"Menciones sugeridas",children:[L&&W.length===0&&t.jsx("li",{style:il,children:"Buscando…"}),!L&&W.length===0&&t.jsx("li",{style:il,children:x.query.trim().length===0?"Escribe un nombre o usuario":`Sin coincidencias para “${x.query}”`}),W.map((D,$)=>{var oe,G;return t.jsx("li",{children:t.jsxs("button",{type:"button","data-mention-index":$,onMouseDown:X=>{X.preventDefault(),j(D)},onMouseEnter:()=>U($),style:{width:"100%",textAlign:"left",padding:"8px 10px",border:"none",background:$===T?"color-mix(in srgb, var(--primary, var(--bonsaif-ui-primary, #1f6feb)) 14%, transparent)":"transparent",color:"var(--text-main, var(--bonsaif-ui-text, #24292f))",borderRadius:6,cursor:"pointer",display:"flex",flexDirection:"column",gap:2},children:[t.jsx("span",{style:{fontWeight:600,fontSize:13},children:((oe=D.name)==null?void 0:oe.trim())||`@${D.username}`}),t.jsx("span",{style:{fontSize:11,color:"var(--text-muted, #656d76)"},children:[(G=D.name)!=null&&G.trim()?`@${D.username}`:null,D.email].filter(Boolean).join(" · ")||`@${D.username}`})]})},D.userId)})]}),document.body):null;return t.jsxs("div",{ref:f,style:ku,className:i,children:[t.jsx(zs,{value:ae,onChange:le,placeholder:l,minHeight:s,instanceId:b}),H]})}function Mu({value:e,onChange:r,placeholder:n,minHeight:a,onSearchUsers:s,onMentionsChange:l,className:i,maxSuggestions:c,searchDebounceMs:d,highlightInEditor:u,searchCacheKey:m}){return s?t.jsx(cl,{value:e,onChange:r,onSearchUsers:s,onMentionsChange:l,placeholder:n,minHeight:a,className:i,maxSuggestions:c,searchDebounceMs:d,highlightInEditor:u,searchCacheKey:m}):t.jsx(zs,{value:e,onChange:r,placeholder:n,minHeight:a})}function Tu({title:e,subtitle:r,icon:n,actions:a,children:s,footer:l,className:i="",bodyClassName:c="p-4"}){const d=e||r||n||a;return t.jsxs("section",{className:`overflow-hidden rounded-lg border border-[var(--border)] bg-[var(--bg-card)] ${i}`,children:[d&&t.jsxs("header",{className:"flex items-center justify-between gap-3 border-b border-[var(--border)] px-4 py-3",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[n&&t.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg border border-[var(--border)] bg-[var(--bg-input)] text-[var(--primary)]",children:n}),t.jsxs("div",{className:"min-w-0",children:[e&&t.jsx("h3",{className:"truncate text-sm font-semibold text-[var(--text-main)]",children:e}),r&&t.jsx("div",{className:"truncate text-xs text-[var(--text-muted)]",children:r})]})]}),a&&t.jsx("div",{className:"shrink-0",children:a})]}),t.jsx("div",{className:c,children:s}),l&&t.jsx("footer",{className:"border-t border-[var(--border)] px-4 py-3",children:l})]})}const $u={neutral:{text:"var(--text-secondary)",bg:"var(--bg-input)",border:"var(--border)"},primary:{text:"var(--primary)",bg:"color-mix(in srgb, var(--primary) 10%, transparent)",border:"color-mix(in srgb, var(--primary) 24%, var(--border))"},success:{text:"#047857",bg:"rgba(16, 185, 129, 0.11)",border:"rgba(16, 185, 129, 0.24)"},warning:{text:"#b45309",bg:"rgba(245, 158, 11, 0.12)",border:"rgba(245, 158, 11, 0.26)"},danger:{text:"var(--danger)",bg:"var(--danger-bg)",border:"color-mix(in srgb, var(--danger) 20%, var(--border))"},info:{text:"#2563eb",bg:"rgba(59, 130, 246, 0.11)",border:"rgba(59, 130, 246, 0.24)"}},Au={xs:"min-h-5 px-1.5 text-[10px]",sm:"min-h-6 px-2 text-xs",md:"min-h-7 px-2.5 text-sm"};function Lu({children:e,tone:r="neutral",size:n="sm",icon:a,dot:s=!1,className:l=""}){const i=$u[r];return t.jsxs("span",{className:`inline-flex max-w-full shrink-0 items-center gap-1.5 rounded-full border font-semibold leading-none ${Au[n]} ${l}`,style:{color:i.text,background:i.bg,borderColor:i.border},children:[s&&t.jsx("span",{"aria-hidden":"true",className:"h-1.5 w-1.5 shrink-0 rounded-full",style:{background:i.text}}),a&&t.jsx("span",{className:"shrink-0",children:a}),t.jsx("span",{className:"min-w-0 truncate",children:e})]})}const dl={neutral:{color:"var(--text-secondary)",background:"var(--bg-input)"},primary:{color:"var(--primary)",background:"color-mix(in srgb, var(--primary) 10%, transparent)"},success:{color:"#047857",background:"rgba(16, 185, 129, 0.11)"},warning:{color:"#b45309",background:"rgba(245, 158, 11, 0.12)"},danger:{color:"var(--danger)",background:"var(--danger-bg)"},info:{color:"#2563eb",background:"rgba(59, 130, 246, 0.11)"}},Du={xs:"min-h-5 px-1.5 pr-6 text-[10px]",sm:"min-h-6 px-2 pr-7 text-xs",md:"min-h-7 px-2.5 pr-8 text-sm"},Iu={xs:"right-1 h-3 w-3",sm:"right-1.5 h-3 w-3",md:"right-2 h-3.5 w-3.5"},Ou={xs:148,sm:164,md:184},Hu={xs:"px-2.5 py-1.5 text-xs",sm:"px-3 py-2 text-sm",md:"px-3.5 py-2.5 text-sm"};function Bu({value:e,options:r,onChange:n,size:a="sm",disabled:s=!1,loading:l=!1,stopPropagation:i=!1,ariaLabel:c="Cambiar estado",title:d="Cambiar estado",className:u,selectClassName:m,menuClassName:b,optionClassName:f,spinnerClassName:g}){const[v,k]=o.useState(!1),[h,C]=o.useState(!1),[M,y]=o.useState(-1),[x,w]=o.useState({}),N=o.useRef(null),A=o.useRef(null),T=o.useRef(null),U=r.find(V=>V.value===e)??r[0],K={...U!=null&&U.tone?dl[U.tone]:void 0,...U==null?void 0:U.style},Z=s||l||r.length===0,L=V=>{i&&V.stopPropagation()},Q=o.useCallback(()=>{k(!1),y(-1)},[]),z=o.useCallback(()=>{const V=N.current;if(!V)return;const B=V.getBoundingClientRect(),le=Math.max(B.width,Ou[a]),j=Math.min(Math.max(r.length,1)*38+12,260),W=window.innerHeight-B.bottom,ae=W<j&&B.top>W,H=Math.min(Math.max(8,B.left+B.width/2-le/2),window.innerWidth-le-8);w({position:"fixed",left:H,top:ae?void 0:B.bottom+6,bottom:ae?window.innerHeight-B.top+6:void 0,width:le,zIndex:9999})},[r.length,a]),se=o.useCallback(V=>{V.disabled||(n(V.value),Q())},[Q,n]);o.useEffect(()=>C(!0),[]),o.useEffect(()=>{if(!v)return;z();const V=r.findIndex(B=>B.value===e);y(V>=0?V:0)},[v,r,z,e]),o.useEffect(()=>{if(!v)return;function V(B){var j,W;const le=B.target;!((j=N.current)!=null&&j.contains(le))&&!((W=A.current)!=null&&W.contains(le))&&Q()}return document.addEventListener("mousedown",V),()=>document.removeEventListener("mousedown",V)},[Q,v]),o.useEffect(()=>{if(v)return window.addEventListener("resize",z),window.addEventListener("scroll",z,!0),()=>{window.removeEventListener("resize",z),window.removeEventListener("scroll",z,!0)}},[v,z]),o.useEffect(()=>{if(M<0||!T.current)return;const V=T.current.children[M];V==null||V.scrollIntoView({block:"nearest"})},[M]);function re(V){if(!Z){if(!v){["Enter"," ","ArrowDown","ArrowUp"].includes(V.key)&&(V.preventDefault(),k(!0));return}if(V.key==="Escape"){V.preventDefault(),Q();return}if(V.key==="ArrowDown"){V.preventDefault(),y(B=>Math.min(B+1,r.length-1));return}if(V.key==="ArrowUp"){V.preventDefault(),y(B=>Math.max(B-1,0));return}if(V.key==="Enter"||V.key===" "){V.preventDefault();const B=r[M];B&&se(B)}}}const R=t.jsx("div",{ref:A,role:"listbox","aria-label":c,className:jt("overflow-hidden rounded-xl border shadow-xl backdrop-blur-md",b),style:{...x,background:"color-mix(in srgb, var(--bg-card) 92%, transparent)",borderColor:"var(--border)",color:"var(--text-main)"},onClick:L,onMouseDown:L,onPointerDown:L,children:t.jsx("div",{ref:T,className:"max-h-64 overflow-y-auto p-1",style:{scrollbarWidth:"thin",scrollbarColor:"var(--border) transparent",overscrollBehavior:"contain"},children:r.map((V,B)=>{const le=V.value===e,j=B===M,W={...V.tone?dl[V.tone]:void 0,...V.style};return t.jsxs("button",{type:"button",role:"option","aria-selected":le,disabled:V.disabled,onMouseEnter:()=>!V.disabled&&y(B),onMouseDown:ae=>{ae.preventDefault(),se(V)},className:jt("flex w-full items-center gap-2 rounded-lg font-medium text-left transition-colors disabled:cursor-not-allowed disabled:opacity-45",Hu[a],le?V.className:void 0,f),style:{...le?W:void 0,background:le?W.background??"color-mix(in srgb, var(--primary) 12%, transparent)":j?"var(--bg-hover)":"transparent",color:le?W.color??"var(--primary)":"var(--text-main)"},children:[t.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center",children:le?t.jsx(q.HiCheck,{className:"h-4 w-4"}):null}),t.jsx("span",{className:"min-w-0 flex-1 truncate",children:V.label})]},V.value)})})});return t.jsxs("span",{ref:N,className:jt("relative inline-flex shrink-0 items-center",u),onKeyDown:re,onClick:L,onPointerDown:L,children:[t.jsx("button",{type:"button",disabled:Z,"aria-label":c,"aria-haspopup":"listbox","aria-expanded":v,title:d,onClick:()=>!Z&&k(V=>!V),className:jt("inline-flex items-center rounded-full border border-transparent font-medium leading-none outline-none transition-colors hover:border-current focus:border-current disabled:cursor-wait disabled:opacity-70",Du[a],U==null?void 0:U.className,m),style:K,children:t.jsx("span",{className:"min-w-0 truncate",children:(U==null?void 0:U.label)??e})}),t.jsx(q.HiChevronDown,{"aria-hidden":"true",className:jt("pointer-events-none absolute opacity-70 transition-transform",Iu[a],v?"rotate-180":"rotate-0")}),l&&t.jsx("span",{"aria-hidden":"true",className:jt("absolute -right-1 -top-1 h-2.5 w-2.5 rounded-full border border-current border-t-transparent animate-spin",g)}),v&&h&&dt.createPortal(R,document.body)]})}function Fu({tabs:e,activeTabId:r,defaultActiveTabId:n,onTabChange:a,ariaLabel:s="Pestanas",variant:l="underline",className:i="",listClassName:c="",panelClassName:d=""}){const u=e.find(v=>!v.disabled)??e[0],m=r??n??(u==null?void 0:u.id),b=e.find(v=>v.id===m)??u,f=v=>{v.disabled||a==null||a(v.id)},g=v=>{const k=e.filter(C=>!C.disabled);if(!k.length||!b)return;const h=k.findIndex(C=>C.id===b.id);(v.key==="ArrowRight"||v.key==="ArrowDown")&&(v.preventDefault(),f(k[(h+1)%k.length])),(v.key==="ArrowLeft"||v.key==="ArrowUp")&&(v.preventDefault(),f(k[(h-1+k.length)%k.length])),v.key==="Home"&&(v.preventDefault(),f(k[0])),v.key==="End"&&(v.preventDefault(),f(k[k.length-1]))};return t.jsxs("div",{className:i,children:[t.jsx("div",{role:"tablist","aria-label":s,onKeyDown:g,className:`flex min-w-0 gap-1 overflow-x-auto ${l==="underline"?"border-b border-[var(--border)]":"rounded-lg border border-[var(--border)] bg-[var(--bg-input)] p-1"} ${c}`,children:e.map(v=>{const k=v.id===(b==null?void 0:b.id);return t.jsxs("button",{type:"button",role:"tab","aria-selected":k,"aria-controls":`${v.id}-panel`,id:`${v.id}-tab`,disabled:v.disabled,tabIndex:k?0:-1,onClick:()=>f(v),className:`inline-flex min-h-8 shrink-0 items-center justify-center gap-1.5 whitespace-nowrap px-2.5 text-sm font-semibold transition-colors focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 ${l==="underline"?"border-b-2":"rounded-md border"}`,style:{color:k?"var(--primary)":"var(--text-muted)",borderColor:k?"var(--primary)":"transparent",background:l==="pills"&&k?"var(--bg-card)":"transparent"},children:[v.icon&&t.jsx("span",{className:"shrink-0",children:v.icon}),t.jsx("span",{children:v.label}),v.badge&&t.jsx("span",{className:"shrink-0",children:v.badge})]},v.id)})}),(b==null?void 0:b.content)!==void 0&&t.jsx("div",{role:"tabpanel",id:`${b.id}-panel`,"aria-labelledby":`${b.id}-tab`,className:`pt-4 ${d}`,children:b.content})]})}function Vt(...e){return e.filter(Boolean).join(" ")}function Pu({steps:e,activeStepId:r,initialStepId:n,completedStepIds:a,defaultCompletedStepIds:s=[],onActiveStepChange:l,onCompletedStepIdsChange:i,onBlockedStep:c,allowBackNavigation:d=!0,showFooter:u=!0,previousLabel:m="Anterior",nextLabel:b="Siguiente",blockedNextLabel:f="Completa este paso",className:g="",headerClassName:v="",contentClassName:k="",footerClassName:h=""}){var G;const C=((G=e[0])==null?void 0:G.id)??"",[M,y]=o.useState(n??C),[x,w]=o.useState(s),N=r??M,A=a??x,T=o.useMemo(()=>new Set(A),[A]),U=Math.max(0,e.findIndex(X=>X.id===N)),K=e[U]??e[0],Z=e.length<=1?100:U/(e.length-1)*100,L=X=>{a||w(X),i==null||i(X)},Q=X=>{const S=e.find(O=>O.id===X);S&&(r||y(X),l==null||l(X,S))},z=X=>T.has(X),se=X=>e.slice(0,X).find(S=>!S.optional&&!T.has(S.id)),re=X=>{const S=e[X];return!S||S.disabled?!1:X===U||d&&X<U?!0:!se(X)},R=X=>{const S=e.findIndex(O=>O.id===X);return S>=0&&re(S)},V=X=>{const S=e.findIndex(O=>O.id===X);if(S<0)return!1;if(!re(S)){const O=se(S);return O&&(c==null||c(e[S],O)),!1}return Q(X),!0},B=(X=K==null?void 0:K.id)=>{!X||T.has(X)||L([...A,X])},le=(X=K==null?void 0:K.id)=>{if(!X)return;const S=e.findIndex(I=>I.id===X),O=A.filter(I=>{const te=e.findIndex(P=>P.id===I);return te>=0&&te<S});L(O),S>=0&&U>S&&Q(X)},j=()=>U<=0?!1:V(e[U-1].id),W=()=>{const X=e[U+1];return X?V(X.id):!1},ae={activeStep:K,activeIndex:U,completedStepIds:A,isCompleted:z,isUnlocked:R,completeStep:B,uncompleteStep:le,goToStep:V,goNext:W,goPrevious:j};if(!K)return null;const H=e[U+1],D=U>0,$=H?R(H.id):!1,oe=typeof K.content=="function"?K.content(ae):K.content;return t.jsxs("section",{className:Vt("overflow-hidden rounded-lg border border-[var(--border)] bg-[var(--bg-card)]",g),children:[t.jsxs("div",{className:Vt("border-b border-[var(--border)] bg-[var(--bg-input)]",v),children:[t.jsx("div",{className:"relative h-1 overflow-hidden bg-[var(--border)]/55",children:t.jsx("div",{className:"h-full rounded-r-full bg-[var(--primary)] transition-[width] duration-500 ease-out",style:{width:`${Z}%`}})}),t.jsx("div",{className:"grid gap-2 p-2",style:{gridTemplateColumns:`repeat(${e.length}, minmax(0, 1fr))`},children:e.map((X,S)=>{const O=X.id===K.id,I=z(X.id),te=re(S),P=se(S);return t.jsxs("button",{type:"button",disabled:!te,"aria-current":O?"step":void 0,"aria-disabled":!te,title:!te&&P?`Completa ${P.title}`:X.title,onClick:()=>V(X.id),className:Vt("group relative min-h-16 min-w-0 overflow-hidden rounded-md border p-3 text-left transition-all duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--primary)]/35 disabled:cursor-not-allowed",O&&"border-[var(--primary)] bg-[var(--bg-card)] shadow-sm",I&&!O&&"border-[var(--primary)]/35 bg-[var(--bg-card)]",!O&&!I&&te&&"border-transparent bg-[var(--bg-card)]/45 hover:border-[var(--border)] hover:bg-[var(--bg-card)]",!te&&"border-transparent bg-[var(--bg-card)]/35 opacity-60"),children:[t.jsx("span",{className:Vt("absolute inset-x-0 top-0 h-0.5 origin-left scale-x-0 bg-[var(--primary)] transition-transform duration-300",O&&"scale-x-100")}),t.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:Vt("grid h-7 w-7 shrink-0 place-items-center rounded-full border text-xs font-bold transition-all duration-200",O&&"border-[var(--primary)] bg-[var(--primary)] text-[var(--primary-fg)]",I&&!O&&"border-[var(--primary)] bg-[var(--primary)]/12 text-[var(--primary)]",!I&&!O&&te&&"border-[var(--border)] text-[var(--text-muted)]",!te&&"border-[var(--border)] text-[var(--text-muted)]"),children:I?t.jsx(q.HiCheck,{className:"h-4 w-4"}):te?S+1:t.jsx(q.HiLockClosed,{className:"h-3.5 w-3.5"})}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsxs("span",{className:Vt("block truncate text-xs font-semibold transition-colors duration-200",O?"text-[var(--text-main)]":"text-[var(--text-secondary)]"),children:[S+1,". ",X.title]}),X.description&&t.jsx("span",{className:"mt-1 block truncate text-[11px] text-[var(--text-muted)]",children:X.description})]}),X.badge&&t.jsx("span",{className:"shrink-0",children:X.badge})]})]},X.id)})})]}),t.jsx("div",{className:Vt("min-h-72 animate-[stepWizardIn_220ms_ease-out] p-5",k),children:oe},K.id),u&&t.jsxs("div",{className:Vt("flex flex-wrap items-center justify-between gap-3 border-t border-[var(--border)] bg-[var(--bg-input)] px-4 py-3",h),children:[t.jsx(Ue,{variant:"secondary",height:38,padding:"0 14px",icon:t.jsx(q.HiChevronLeft,{}),disabled:!D,onClick:j,children:m}),t.jsxs("div",{className:"flex items-center gap-3 text-xs text-[var(--text-muted)]",children:[t.jsxs("span",{children:["Paso ",U+1," de ",e.length]}),t.jsx("span",{className:"h-1 w-1 rounded-full bg-[var(--border)]"}),t.jsxs("span",{children:[A.length," completados"]})]}),t.jsx(Ue,{height:38,padding:"0 14px",icon:t.jsx(q.HiChevronRight,{}),disabled:!H||!$,onClick:W,children:H&&!$?f:b})]})]})}const _u={sm:"px-2.5 py-1.5 text-xs leading-5",md:"px-2.5 py-1.5 text-sm leading-5",lg:"px-3 py-2 text-sm leading-6"};function zu(e,r){if(e){if(typeof e=="function"){e(r);return}e.current=r}}function Wu(e){const r=getComputedStyle(e),n=Number.parseFloat(r.lineHeight),a=Number.parseFloat(r.paddingTop)+Number.parseFloat(r.paddingBottom),s=Number.parseFloat(r.borderTopWidth)+Number.parseFloat(r.borderBottomWidth);return{lineHeight:Number.isFinite(n)?n:20,paddingY:Number.isFinite(a)?a:12,borderY:Number.isFinite(s)?s:2}}function ul(e,r){const{lineHeight:n,paddingY:a,borderY:s}=Wu(e);return Math.ceil(r*n+a+s)}const fl=o.forwardRef(function({className:r="",size:n="md",status:a="default",maxHeight:s,maxRows:l,minRows:i=1,style:c,value:d,defaultValue:u,onInput:m,...b},f){const g=o.useRef(null),v=a==="error"?"var(--danger)":a==="success"?"#16a34a":"var(--border)",k=o.useCallback(()=>{const h=g.current;if(!h)return;h.style.height="auto";const C=h.scrollHeight,M=ul(h,i),y=s??(l!==void 0?ul(h,l):void 0),x=y!==void 0?Math.min(Math.max(C,M),y):Math.max(C,M);h.style.height=`${x}px`,h.style.overflowY=y!==void 0&&C>y?"auto":"hidden"},[s,l,i]);return o.useLayoutEffect(()=>{k()},[k,d,u]),o.useEffect(()=>{const h=g.current;if(!h||typeof ResizeObserver>"u")return;const C=new ResizeObserver(()=>k());return C.observe(h),()=>C.disconnect()},[k]),t.jsx("textarea",{...b,ref:h=>{g.current=h,zu(f,h)},rows:i,value:d,defaultValue:u,"aria-invalid":a==="error"||b["aria-invalid"],onInput:h=>{k(),m==null||m(h)},style:{...c,borderColor:v,minHeight:void 0},className:`w-full resize-none overflow-hidden rounded-lg border bg-[var(--bg-input)] text-[var(--text-main)] outline-none placeholder:text-[var(--text-muted)] transition-colors focus:border-[var(--primary)] disabled:cursor-not-allowed disabled:opacity-60 ${_u[n]} ${r}`})});function ju({label:e,containerClassName:r="",helperText:n,helperDisplay:a,error:s,labelAction:l,required:i,className:c="",status:d,...u}){return t.jsx($n,{label:e,required:i,helperText:n,helperDisplay:a,error:s,labelAction:l,className:r,children:t.jsx(fl,{...u,required:i,status:s?"error":d,className:`w-full ${c}`})})}const qu={sm:"min-h-20 px-2.5 py-1.5 text-xs leading-5",md:"min-h-24 px-2.5 py-2 text-sm leading-5",lg:"min-h-32 px-3 py-2.5 text-sm leading-6"},Uu={none:"resize-none",vertical:"resize-y",horizontal:"resize-x",both:"resize"};function Vu(e,r){if(e){if(typeof e=="function"){e(r);return}e.current=r}}function Yu(e,r){return e!==void 0?String(e).length:r!==void 0?String(r).length:0}const bl=o.forwardRef(function({className:r="",wrapperClassName:n="",size:a="md",resize:s="vertical",autoResize:l=!1,minRows:i,maxRows:c,showCount:d=!1,maxCount:u,status:m="default",icon:b,action:f,style:g,value:v,defaultValue:k,maxLength:h,onInput:C,...M},y){const x=o.useRef(null),w=Yu(v,k),N=u??h,A=!!(b||f||d),T=m==="error"?"var(--danger)":m==="success"?"#16a34a":"var(--border)",U={...g??{},...i?{minHeight:`${i*24+18}px`}:null,...c?{maxHeight:`${c*24+18}px`}:null},K=()=>{const L=x.current;!L||!l||(L.style.height="auto",L.style.height=`${L.scrollHeight}px`)};o.useEffect(K,[l,v]);const Z=t.jsx("textarea",{...M,ref:L=>{x.current=L,Vu(y,L)},value:v,defaultValue:k,maxLength:h,"aria-invalid":m==="error"||M["aria-invalid"],onInput:L=>{K(),C==null||C(L)},style:{...U,borderColor:T},className:`w-full rounded-lg border bg-[var(--bg-input)] text-[var(--text-main)] outline-none placeholder:text-[var(--text-muted)] transition-colors focus:border-[var(--primary)] disabled:cursor-not-allowed disabled:opacity-60 ${qu[a]} ${Uu[l?"none":s]} ${b?"pl-8":""} ${f?"pr-10":""} ${r}`});return A?t.jsxs("span",{className:`relative block ${n}`,children:[b&&t.jsx("span",{className:"pointer-events-none absolute left-2.5 top-2.5 flex h-4 w-4 items-center justify-center text-[var(--text-muted)]",children:b}),Z,f&&t.jsx("span",{className:"absolute right-2 top-2 flex items-center justify-center",children:f}),d&&t.jsxs("span",{className:"absolute bottom-1.5 right-2 rounded bg-[var(--bg-input)] px-1.5 text-[10px] font-semibold text-[var(--text-muted)]",children:[w,N?`/${N}`:""]})]}):Z});function Xu({label:e,containerClassName:r="",helperText:n,helperDisplay:a,error:s,labelAction:l,required:i,className:c="",status:d,...u}){return t.jsx($n,{label:e,required:i,helperText:n,helperDisplay:a,error:s,labelAction:l,className:r,children:t.jsx(bl,{...u,required:i,status:s?"error":d,className:`w-full ${c}`})})}const ml=[{bg:"#dbeafe",text:"#1e40af",border:"#bfdbfe"},{bg:"#dcfce7",text:"#166534",border:"#bbf7d0"},{bg:"#fce7f3",text:"#9d174d",border:"#fbcfe8"},{bg:"#fef9c3",text:"#854d0e",border:"#fef08a"},{bg:"#ede9fe",text:"#5b21b6",border:"#ddd6fe"},{bg:"#ffedd5",text:"#9a3412",border:"#fed7aa"},{bg:"#cffafe",text:"#155e75",border:"#a5f3fc"},{bg:"#f0fdf4",text:"#14532d",border:"#bbf7d0"}];function Ku(e){return ml[e%ml.length]}let Gu=0;function lo(){return++Gu}function pl(e,r){return r?r instanceof RegExp?r.test(e):r(e):!0}function Zu(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Qu(e,r){const n=r.filter(Boolean);if(n.length===0)return[e.trim()].filter(Boolean);const a=new RegExp(`${n.map(s=>Zu(s)).join("|")}|\\r?\\n`,"g");return e.split(a).map(s=>s.trim()).filter(Boolean)}function Ju({value:e,defaultValue:r,onChange:n,placeholder:a="Escribe y presiona Enter…",disabled:s=!1,className:l="",delimiters:i=[","],maxTags:c,allowDuplicates:d=!1,validate:u,label:m,helperText:b,helperDisplay:f="inline",error:g,required:v=!1}){const k=e!==void 0,h=!!g,C=!!b&&f==="tooltip"&&!h,[M,y]=o.useState(()=>(r??[]).map((I,te)=>({id:lo(),value:I.trim(),colorIndex:te})));o.useEffect(()=>{k&&y(I=>{const te=e??[],P=new Map(I.map(ce=>[ce.value,ce]));return te.map((ce,he)=>P.get(ce)??{id:lo(),value:ce,colorIndex:he})})},[k,e]);const x=M,[w,N]=o.useState(""),[A,T]=o.useState(null),[U,K]=o.useState(""),[Z,L]=o.useState(!1),[Q,z]=o.useState(!1),se=o.useRef(null),re=o.useRef(null),R=o.useRef(null);function V(){z(!0),setTimeout(()=>z(!1),400)}function B(I){y(I),n==null||n(I.map(te=>te.value))}function le(I){let te=x,P=!1,ce=!1;for(const he of I){const ie=he.trim();if(ie){if(c!==void 0&&te.length>=c){ce=!0;break}if(!d&&te.some(ge=>ge.value.toLowerCase()===ie.toLowerCase())){ce=!0;continue}if(!pl(ie,u)){ce=!0;continue}te=[...te,{id:lo(),value:ie,colorIndex:te.length}],P=!0}}return P&&B(te),ce&&V(),P}function j(I){return le([I])}function W(I){const te=x.filter(P=>P.id!==I);B(te.map((P,ce)=>({...P,colorIndex:ce})))}function ae(I,te){const P=te.trim();if(T(null),K(""),!P){W(I);return}if(!(!d&&x.some(ce=>ce.id!==I&&ce.value.toLowerCase()===P.toLowerCase()))){if(!pl(P,u)){V();return}B(x.map(ce=>ce.id===I?{...ce,value:P}:ce))}}function H(I){s||(T(I.id),K(I.value),setTimeout(()=>{var te;return(te=re.current)==null?void 0:te.select()},0))}function D(I){if(I.key==="Enter"||i.includes(I.key)){I.preventDefault(),j(w)&&N("");return}if(I.key==="Backspace"&&w===""&&x.length>0){I.preventDefault();const te=x[x.length-1];W(te.id)}}function $(I,te){if(I.key==="Enter"){I.preventDefault(),ae(te,U),setTimeout(()=>{var P;return(P=se.current)==null?void 0:P.focus()},0);return}I.key==="Escape"&&(I.preventDefault(),T(null),K(""),setTimeout(()=>{var P;return(P=se.current)==null?void 0:P.focus()},0))}function oe(){var I;s||(I=se.current)==null||I.focus()}function G(I){if(s)return;const te=I.clipboardData.getData("text");if(!te||!(i.some(ie=>ie&&te.includes(ie))||te.includes(`
31
- `)))return;I.preventDefault();const ce=Qu(te,i);le(ce)&&N("")}function X(){const I=w.trim();I&&j(I)&&N("")}const S=h?"var(--danger)":Z?"var(--primary)":"var(--border)",O=c!==void 0&&x.length>=c;return t.jsxs("div",{className:`flex flex-col gap-2 ${l}`,children:[(m||v||C)&&t.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-semibold uppercase text-[var(--text-muted)]",children:[m&&t.jsx("span",{children:m}),v&&t.jsx("span",{className:"text-[var(--danger)]",children:"*"}),C?t.jsx(xr,{content:b}):null]}),t.jsxs("div",{ref:R,onClick:oe,onFocus:()=>L(!0),onBlur:I=>{var te;(te=R.current)!=null&&te.contains(I.relatedTarget)||(L(!1),A!==null&&ae(A,U),A===null&&X())},style:{borderColor:S},className:`
30
+ `)&&d(f)==="matched")return!0;if(f.nodeType===Node.TEXT_NODE)return u(f);if(f.nodeType!==Node.ELEMENT_NODE)return!1;const v=f;if(v.tagName==="BR")return i(v,0),d(v.nextSibling??void 0)==="matched";const k=Array.from(f.childNodes);for(let h=0;h<k.length;h+=1){const A=k[h],$=h>0&&A.nodeType===Node.ELEMENT_NODE&&tl(A,e);if(m(A,$))return!0}return!1},b=Array.from(e.childNodes);for(let f=0;f<b.length;f+=1){const g=b[f],v=f>0&&g.nodeType===Node.ELEMENT_NODE&&tl(g,e);if(m(g,v))break}if((r==null?void 0:r.locatePlain)===n.length&&!a){const f=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT);let g=f.nextNode(),v=g;for(;v;)g=v,v=f.nextNode();g&&(a={node:g,offset:g.data.length})}return{plain:n,locate:a,domOffset:s}}function co(e){return io(e).plain}function Cr(e,r){return r<0?null:io(e,{locatePlain:r}).locate??null}function qn(e,r,n){return e!==r&&!e.contains(r)?-1:io(e,{domPoint:{container:r,offset:n}}).domOffset??-1}function rl(e,r){const{triggerIndex:n,caretIndex:a,username:s}=r;if(a<n)return null;const l=Cr(e,n),i=Cr(e,a);if(!l||!i)return null;const c=e.ownerDocument,d=c.createRange();d.setStart(l.node,l.offset),d.setEnd(i.node,i.offset),d.deleteContents();const u=Js({name:r.display,username:s}),m=c.createElement("span");m.className="mention-chip",m.setAttribute("data-username",s.toLowerCase()),r.userId&&m.setAttribute("data-userid",String(r.userId)),m.contentEditable="false",m.textContent=u,m.title=`@${s}`;const b=c.createTextNode(" "),f=c.createDocumentFragment();f.append(m,b),d.insertNode(f),lo(e);const g=c.defaultView,v=g==null?void 0:g.getSelection();if(v){const h=c.createRange();h.setStart(b,b.data.length),h.collapse(!0),v.removeAllRanges(),v.addRange(h)}const k=v!=null&&v.rangeCount?qn(e,v.getRangeAt(0).startContainer,v.getRangeAt(0).startOffset):n+u.length+1;return{caretPlainOffset:k>=0?k:n+u.length+1}}function nl(e,r){const n=e.ownerDocument,a=n.defaultView;if(!a)return;const s=a.getSelection();if(!s)return;const l=n.createRange(),i=Cr(e,r);i?(l.setStart(i.node,i.offset),l.collapse(!0)):(l.selectNodeContents(e),l.collapse(!1)),s.removeAllRanges(),s.addRange(l)}function Un(e){return e instanceof HTMLElement&&e.classList.contains("mention-chip")}function al(e,r){let n=e;for(;n&&n.nodeType===Node.TEXT_NODE&&!(n.textContent??"").replace(/\u00a0/g," ").trim();)n=r==="prev"?n.previousSibling:n.nextSibling;return n}function ol(e){var s;const r=e.ownerDocument,n=(s=r.defaultView)==null?void 0:s.getSelection();if(!n)return;const a=r.createRange();a.selectNode(e),n.removeAllRanges(),n.addRange(a),e.classList.add("is-selected")}function Er(e=document){var r;(r=e.querySelectorAll)==null||r.call(e,".mention-chip.is-selected").forEach(n=>{n.classList.remove("is-selected")})}function Vn(e){var a;const r=(a=e.ownerDocument.defaultView)==null?void 0:a.getSelection();e.querySelectorAll(".mention-chip").forEach(s=>{let l=!1;if(r&&r.rangeCount>0)try{const i=r.getRangeAt(0);(!r.isCollapsed&&i.intersectsNode(s)||r.isCollapsed&&i.startContainer===s&&i.endContainer===s)&&(l=!0)}catch{l=!1}s.classList.toggle("is-selected",l)})}function sl(e){var s;const r=e.ownerDocument,n=(s=r.defaultView)==null?void 0:s.getSelection();if(!n)return;const a=r.createRange();a.selectNodeContents(e),n.removeAllRanges(),n.addRange(a),Vn(e)}function ll(e){const r=e.cloneContents();return r.querySelectorAll(".mention-chip").forEach(n=>n.remove()),(r.textContent??"").replace(/\u00a0/g," ").trim().length>0}function il(e){var a;const r=(a=e.ownerDocument.defaultView)==null?void 0:a.getSelection();if(!r||r.isCollapsed||r.rangeCount===0)return!1;const n=r.getRangeAt(0);return e.contains(n.commonAncestorContainer)?(n.deleteContents(),Er(e),!0):!1}function Yn(e){var m,b;const r=e.ownerDocument,n=e.parentNode;if(!n)return;const a=(f,g)=>{let v=f;for(;v&&v.nodeType===Node.TEXT_NODE&&(v.textContent??"")==="";){const k=v;v=v[g],k.remove()}return v},s=a(e.nextSibling,"nextSibling");if(s&&s.nodeType===Node.TEXT_NODE&&/^( |\u00a0)/.test(s.textContent??"")){const f=s;(f.data.length??0)<=1?f.remove():f.data=f.data.slice(1)}const l=a(e.previousSibling,"previousSibling"),i=n,c=Array.from(n.childNodes).indexOf(e);e.remove();const d=(m=r.defaultView)==null?void 0:m.getSelection();if(!d)return;const u=r.createRange();if(l)if(l.nodeType===Node.TEXT_NODE){const f=((b=l.textContent)==null?void 0:b.length)??0;u.setStart(l,f)}else u.setStartAfter(l);else i.childNodes[c]?u.setStart(i,c):(u.selectNodeContents(i),u.collapse(!1));u.collapse(!0),d.removeAllRanges(),d.addRange(u)}function cl(e){var l;const r=(l=e.ownerDocument.defaultView)==null?void 0:l.getSelection();if(!r||!r.isCollapsed||r.rangeCount===0)return null;const n=r.getRangeAt(0);if(!e.contains(n.startContainer))return null;const{startContainer:a,startOffset:s}=n;if(a.nodeType===Node.TEXT_NODE){const i=a.textContent??"",c=al(a.previousSibling,"prev");return Un(c)&&(s===0||s===1&&(i.charAt(0)===" "||i.charAt(0)===" "))?c:null}if(a.nodeType===Node.ELEMENT_NODE){const i=a.childNodes;let c=s-1;for(;c>=0;){const d=i[c];if(Un(d))return d;if(d.nodeType===Node.TEXT_NODE&&!(d.textContent??"").replace(/\u00a0/g," ").trim()){c-=1;continue}break}}return null}function dl(e){var l;const r=(l=e.ownerDocument.defaultView)==null?void 0:l.getSelection();if(!r||!r.isCollapsed||r.rangeCount===0)return null;const n=r.getRangeAt(0);if(!e.contains(n.startContainer))return null;const{startContainer:a,startOffset:s}=n;if(a.nodeType===Node.TEXT_NODE){const i=a.textContent??"";if(s>=i.length){const c=al(a.nextSibling,"next");if(Un(c))return c}return null}if(a.nodeType===Node.ELEMENT_NODE){const i=a.childNodes;let c=s;for(;c<i.length;){const d=i[c];if(Un(d))return d;if(d.nodeType===Node.TEXT_NODE&&!(d.textContent??"").replace(/\u00a0/g," ").trim()){c+=1;continue}break}}return null}function uo(e){var s;const r=(s=e.ownerDocument.defaultView)==null?void 0:s.getSelection();if(!r||r.isCollapsed||r.rangeCount===0)return[];const n=r.getRangeAt(0);return e.contains(n.commonAncestorContainer)?Array.from(e.querySelectorAll(".mention-chip")).filter(l=>{try{return n.intersectsNode(l)}catch{return!1}}):[]}const fo=280,Xn=6,ul=260,$u=new Set(["ArrowDown","ArrowUp","Enter","Tab","Escape"]),fl=4,Au={position:"relative"},Lu={position:"fixed",zIndex:11050,minWidth:ul,overflowY:"auto",background:"var(--bg-card, var(--bonsaif-ui-surface, #fff))",border:"1px solid var(--border, var(--bonsaif-ui-border, #d0d7de))",borderRadius:10,boxShadow:"0 12px 32px rgba(0,0,0,0.18)",padding:4},bl={padding:"10px 12px",fontSize:12,color:"var(--text-muted, #656d76)"};function Du(e){return Array.from(document.querySelectorAll(`[data-bonsaif-rich-instance="${CSS.escape(e)}"]`))}function Iu(e,r){const n=Math.max(8,Math.min(e.left,window.innerWidth-ul-8)),a=r==null?void 0:r.getBoundingClientRect(),s=a?Math.min(window.innerHeight-8,a.bottom):window.innerHeight-8,l=a?Math.max(8,a.top):8,i=s-e.bottom-Xn,c=e.top-l-Xn;return i<Math.min(fo,160)&&c>i?{left:n,bottom:window.innerHeight-e.top+Xn,maxHeight:Math.max(120,Math.min(fo,c))}:{left:n,top:e.bottom+Xn,maxHeight:Math.max(120,Math.min(fo,i))}}function ml({value:e,onChange:r,onSearchUsers:n,onMentionsChange:a,minHeight:s,placeholder:l,className:i,maxSuggestions:c=8,searchDebounceMs:d=140,highlightInEditor:u=!1,searchCacheKey:m=""}){const b=o.useId().replace(/:/g,""),f=o.useRef(null),g=o.useRef(null),v=o.useRef(new Map),k=o.useRef(n);k.current=n;const h=o.useRef(null),A=o.useRef(0),$=o.useRef([]),N=o.useRef(null),[T,x]=o.useState(null),[y,L]=o.useState([]),[w,W]=o.useState(0),[X,Z]=o.useState([]),[D,Q]=o.useState(!1),[j,se]=o.useState(!1);A.current=w,o.useEffect(()=>{se(!0)},[]);const te=(T==null?void 0:T.query)??null;o.useEffect(()=>{if(te===null){L([]);return}const I=te.trim(),E=`${m}|${I.toLowerCase()||"*"}`,oe=v.current.get(E);if(oe){L(oe),Q(!1),W(0);return}const K=new AbortController;Q(!0);const Y=window.setTimeout(()=>{(async()=>{try{const S=await k.current(I,{signal:K.signal,limit:c});if(K.signal.aborted)return;const H=Array.isArray(S)?S:[];v.current.set(E,H),L(H),W(0)}catch{K.signal.aborted||L([])}finally{K.signal.aborted||Q(!1)}})()},d);return()=>{K.abort(),window.clearTimeout(Y)}},[te,c,d,m]);const ee=o.useRef(a);ee.current=a,o.useEffect(()=>{var I;(I=ee.current)==null||I.call(ee,Rs(X))},[X]);const U=o.useCallback(()=>{const I=Du(b);if(I.length===0)return null;const E=window.getSelection();if(E!=null&&E.rangeCount){const K=E.getRangeAt(0).startContainer;for(const Y of I)if(Y.contains(K))return Y}const oe=document.activeElement;for(const K of I)if(oe===K||oe&&K.contains(oe))return K;for(const K of I)if(K.closest('[role="dialog"]'))return K;return I[0]??null},[b]),J=o.useCallback(()=>{const I=U(),E=window.getSelection();if(!I||!E||E.rangeCount===0){x(null);return}const oe=E.getRangeAt(0);if(!I.contains(oe.startContainer)){x(null);return}const K=qn(I,oe.startContainer,oe.startOffset);if(K<0){x(null);return}const Y=ao(I,K);if(!Y){x(null);return}const S=oe.getBoundingClientRect(),H=S.width===0&&S.height===0?(()=>{const re=document.createRange();return re.selectNodeContents(oe.startContainer),re.collapse(!0),re.getBoundingClientRect()})():S;h.current={query:Y.query,caretIndex:Y.caretIndex,triggerIndex:Y.triggerIndex};const O=Iu(H,I);x(re=>{const z={query:Y.query,...O};return re&&re.query===z.query&&re.top===z.top&&re.bottom===z.bottom&&re.left===z.left&&re.maxHeight===z.maxHeight?re:z})},[U]),ce=o.useCallback(I=>{r(I),J()},[r,J]);o.useEffect(()=>{const I=E=>{if($u.has(E.key))return;const oe=U(),K=E.target;!oe||!K||!oe.contains(K)||J()};return document.addEventListener("keyup",I,!0),()=>document.removeEventListener("keyup",I,!0)},[U,J]);const C=o.useCallback(I=>{const E=U();if(!E)return;let oe=-1;const K=window.getSelection();if(K&&K.rangeCount>0){const re=K.getRangeAt(0);E.contains(re.startContainer)&&(oe=qn(E,re.startContainer,re.startOffset))}if(oe<0&&h.current&&(oe=h.current.caretIndex),oe<0)return;const Y=ao(E,oe);if(!Y)return;const S=rl(E,{triggerIndex:Y.triggerIndex,caretIndex:oe,username:I.username,display:I.name,userId:I.userId});if(!S)return;lo(E),E.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0}));const H={userId:I.userId,username:I.username,email:I.email??void 0,display:I.name??I.username};Z(re=>{const z=new Map(re.map(de=>[de.userId,de]));return z.set(H.userId,H),Array.from(z.values())}),x(null),h.current=null;const O=S.caretPlainOffset;requestAnimationFrame(()=>{requestAnimationFrame(()=>{var ie,ge;const re=U();if(!re)return;re.focus(),nl(re,O);const z=window.getSelection(),de=z==null?void 0:z.anchorNode,he=de instanceof Element?de.closest(".mention-chip"):(ie=de==null?void 0:de.parentElement)==null?void 0:ie.closest(".mention-chip");if(he!=null&&he.parentNode){const Me=document.createRange(),$e=he.nextSibling;$e&&$e.nodeType===Node.TEXT_NODE?Me.setStart($e,((ge=$e.textContent)==null?void 0:ge.length)??0):Me.setStartAfter(he),Me.collapse(!0),z==null||z.removeAllRanges(),z==null||z.addRange(Me)}})})},[U]);o.useEffect(()=>{const I=new Set(so(e).map(E=>E.toLowerCase()));Z(E=>{const oe=E.filter(K=>I.has(K.username.toLowerCase()));return oe.length===E.length?E:oe})},[e]),o.useEffect(()=>{if(!T)return;const I=E=>{const oe=E.target;if(!oe||f.current&&f.current.contains(oe)||g.current&&g.current.contains(oe))return;const K=U();K&&K.contains(oe)||x(null)};return document.addEventListener("mousedown",I),()=>{document.removeEventListener("mousedown",I)}},[T,U]);const _=o.useMemo(()=>y.slice(0,c),[y,c]);$.current=_,o.useEffect(()=>{if(!T)return;const I=E=>{const oe=U(),K=E.target;if(!oe||!K||!oe.contains(K))return;const Y=$.current;if(!(Y.length===0&&E.key!=="Escape"))if(E.key==="ArrowDown")E.preventDefault(),E.stopPropagation(),W(S=>(S+1)%Math.max(Y.length,1));else if(E.key==="ArrowUp")E.preventDefault(),E.stopPropagation(),W(S=>(S-1+Y.length)%Math.max(Y.length,1));else if(E.key==="Enter"||E.key==="Tab"){const S=Y[A.current];S&&(E.preventDefault(),E.stopPropagation(),C(S))}else E.key==="Escape"&&(E.preventDefault(),E.stopPropagation(),x(null))};return document.addEventListener("keydown",I,!0),()=>document.removeEventListener("keydown",I,!0)},[U,C,T]),o.useEffect(()=>{const I=H=>{H.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0}))},E=H=>{const O=U(),re=H.target;if(!O||!re||!O.contains(re))return;if((H.metaKey||H.ctrlKey)&&H.key.toLowerCase()==="a"){H.preventDefault(),H.stopPropagation(),O.focus(),sl(O);return}if(H.key!=="Backspace"&&H.key!=="Delete")return;const z=window.getSelection();if(z&&!z.isCollapsed&&z.rangeCount>0){const ie=z.getRangeAt(0);if(O.contains(ie.commonAncestorContainer)&&uo(O).length>0&&ll(ie)){H.preventDefault(),H.stopPropagation(),il(O)&&I(O);return}}const de=uo(O);if(de.length>0){H.preventDefault(),H.stopPropagation();for(const ie of de)Yn(ie);Er(O),I(O);return}if(H.key==="Backspace"){const ie=cl(O);if(!ie)return;H.preventDefault(),H.stopPropagation(),Yn(ie),Er(O),I(O);return}const he=dl(O);he&&(H.preventDefault(),H.stopPropagation(),Yn(he),Er(O),I(O))},oe=H=>{const O=U();if(!O)return;const re=H.target;if(!(re instanceof Element)||!O.contains(re))return;const z=re.closest(".mention-chip");if(!(z instanceof HTMLElement)||!O.contains(z)){N.current=null,Er(O);return}H.shiftKey||H.button!==0||(N.current={chip:z,x:H.clientX,y:H.clientY})},K=H=>{const O=N.current;if(!O)return;const re=Math.abs(H.clientX-O.x),z=Math.abs(H.clientY-O.y);(re>fl||z>fl)&&(N.current=null)},Y=H=>{var he;const O=U(),re=N.current;if(N.current=null,!O||!re)return;const z=H.target;if(!(z instanceof Element)||!O.contains(z)||!((he=z.closest(".mention-chip"))!=null&&he.isSameNode(re.chip)))return;const de=window.getSelection();if(de){if(!de.isCollapsed){Vn(O);return}O.focus(),ol(re.chip)}},S=()=>{const H=U();if(!H)return;const O=window.getSelection();!O||O.rangeCount===0||!O.anchorNode||!H.contains(O.anchorNode)||!O.focusNode||!H.contains(O.focusNode)||Vn(H)};return document.addEventListener("keydown",E,!0),document.addEventListener("mousedown",oe,!0),document.addEventListener("mousemove",K,!0),document.addEventListener("mouseup",Y,!0),document.addEventListener("selectionchange",S),()=>{document.removeEventListener("keydown",E,!0),document.removeEventListener("mousedown",oe,!0),document.removeEventListener("mousemove",K,!0),document.removeEventListener("mouseup",Y,!0),document.removeEventListener("selectionchange",S)}},[U]),o.useEffect(()=>{if(!T||!g.current)return;const I=g.current.querySelector(`[data-mention-index="${w}"]`);I==null||I.scrollIntoView({block:"nearest"})},[w,T]);const ae=u?el(e):e,B=T&&j?ct.createPortal(t.jsxs("ul",{ref:g,style:{...Lu,left:T.left,top:T.top,bottom:T.bottom,maxHeight:T.maxHeight},role:"listbox","aria-label":"Menciones sugeridas",children:[D&&_.length===0&&t.jsx("li",{style:bl,children:"Buscando…"}),!D&&_.length===0&&t.jsx("li",{style:bl,children:T.query.trim().length===0?"Escribe un nombre o usuario":`Sin coincidencias para “${T.query}”`}),_.map((I,E)=>{var oe,K;return t.jsx("li",{children:t.jsxs("button",{type:"button","data-mention-index":E,onMouseDown:Y=>{Y.preventDefault(),C(I)},onMouseEnter:()=>W(E),style:{width:"100%",textAlign:"left",padding:"8px 10px",border:"none",background:E===w?"color-mix(in srgb, var(--primary, var(--bonsaif-ui-primary, #1f6feb)) 14%, transparent)":"transparent",color:"var(--text-main, var(--bonsaif-ui-text, #24292f))",borderRadius:6,cursor:"pointer",display:"flex",flexDirection:"column",gap:2},children:[t.jsx("span",{style:{fontWeight:600,fontSize:13},children:((oe=I.name)==null?void 0:oe.trim())||`@${I.username}`}),t.jsx("span",{style:{fontSize:11,color:"var(--text-muted, #656d76)"},children:[(K=I.name)!=null&&K.trim()?`@${I.username}`:null,I.email].filter(Boolean).join(" · ")||`@${I.username}`})]})},I.userId)})]}),document.body):null;return t.jsxs("div",{ref:f,style:Au,className:i,children:[t.jsx(Vs,{value:ae,onChange:ce,placeholder:l,minHeight:s,instanceId:b}),B]})}function Ou({value:e,onChange:r,placeholder:n,minHeight:a,onSearchUsers:s,onMentionsChange:l,className:i,maxSuggestions:c,searchDebounceMs:d,highlightInEditor:u,searchCacheKey:m}){return s?t.jsx(ml,{value:e,onChange:r,onSearchUsers:s,onMentionsChange:l,placeholder:n,minHeight:a,className:i,maxSuggestions:c,searchDebounceMs:d,highlightInEditor:u,searchCacheKey:m}):t.jsx(Vs,{value:e,onChange:r,placeholder:n,minHeight:a})}function Hu({title:e,subtitle:r,icon:n,actions:a,children:s,footer:l,className:i="",bodyClassName:c="p-4"}){const d=e||r||n||a;return t.jsxs("section",{className:`overflow-hidden rounded-lg border border-[var(--border)] bg-[var(--bg-card)] ${i}`,children:[d&&t.jsxs("header",{className:"flex items-center justify-between gap-3 border-b border-[var(--border)] px-4 py-3",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[n&&t.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg border border-[var(--border)] bg-[var(--bg-input)] text-[var(--primary)]",children:n}),t.jsxs("div",{className:"min-w-0",children:[e&&t.jsx("h3",{className:"truncate text-sm font-semibold text-[var(--text-main)]",children:e}),r&&t.jsx("div",{className:"truncate text-xs text-[var(--text-muted)]",children:r})]})]}),a&&t.jsx("div",{className:"shrink-0",children:a})]}),t.jsx("div",{className:c,children:s}),l&&t.jsx("footer",{className:"border-t border-[var(--border)] px-4 py-3",children:l})]})}const Bu={neutral:{text:"var(--text-secondary)",bg:"var(--bg-input)",border:"var(--border)"},primary:{text:"var(--primary)",bg:"color-mix(in srgb, var(--primary) 10%, transparent)",border:"color-mix(in srgb, var(--primary) 24%, var(--border))"},success:{text:"#047857",bg:"rgba(16, 185, 129, 0.11)",border:"rgba(16, 185, 129, 0.24)"},warning:{text:"#b45309",bg:"rgba(245, 158, 11, 0.12)",border:"rgba(245, 158, 11, 0.26)"},danger:{text:"var(--danger)",bg:"var(--danger-bg)",border:"color-mix(in srgb, var(--danger) 20%, var(--border))"},info:{text:"#2563eb",bg:"rgba(59, 130, 246, 0.11)",border:"rgba(59, 130, 246, 0.24)"}},Fu={xs:"min-h-5 px-1.5 text-[10px]",sm:"min-h-6 px-2 text-xs",md:"min-h-7 px-2.5 text-sm"};function Pu({children:e,tone:r="neutral",size:n="sm",icon:a,dot:s=!1,className:l=""}){const i=Bu[r];return t.jsxs("span",{className:`inline-flex max-w-full shrink-0 items-center gap-1.5 rounded-full border font-semibold leading-none ${Fu[n]} ${l}`,style:{color:i.text,background:i.bg,borderColor:i.border},children:[s&&t.jsx("span",{"aria-hidden":"true",className:"h-1.5 w-1.5 shrink-0 rounded-full",style:{background:i.text}}),a&&t.jsx("span",{className:"shrink-0",children:a}),t.jsx("span",{className:"min-w-0 truncate",children:e})]})}const pl={neutral:{color:"var(--text-secondary)",background:"var(--bg-input)"},primary:{color:"var(--primary)",background:"color-mix(in srgb, var(--primary) 10%, transparent)"},success:{color:"#047857",background:"rgba(16, 185, 129, 0.11)"},warning:{color:"#b45309",background:"rgba(245, 158, 11, 0.12)"},danger:{color:"var(--danger)",background:"var(--danger-bg)"},info:{color:"#2563eb",background:"rgba(59, 130, 246, 0.11)"}},_u={xs:"min-h-5 px-1.5 pr-6 text-[10px]",sm:"min-h-6 px-2 pr-7 text-xs",md:"min-h-7 px-2.5 pr-8 text-sm"},zu={xs:"right-1 h-3 w-3",sm:"right-1.5 h-3 w-3",md:"right-2 h-3.5 w-3.5"},Wu={xs:148,sm:164,md:184},ju={xs:"px-2.5 py-1.5 text-xs",sm:"px-3 py-2 text-sm",md:"px-3.5 py-2.5 text-sm"};function qu({value:e,options:r,onChange:n,size:a="sm",disabled:s=!1,loading:l=!1,stopPropagation:i=!1,ariaLabel:c="Cambiar estado",title:d="Cambiar estado",className:u,selectClassName:m,menuClassName:b,optionClassName:f,spinnerClassName:g}){const[v,k]=o.useState(!1),[h,A]=o.useState(!1),[$,N]=o.useState(-1),[T,x]=o.useState({}),y=o.useRef(null),L=o.useRef(null),w=o.useRef(null),W=r.find(U=>U.value===e)??r[0],X={...W!=null&&W.tone?pl[W.tone]:void 0,...W==null?void 0:W.style},Z=s||l||r.length===0,D=U=>{i&&U.stopPropagation()},Q=o.useCallback(()=>{k(!1),N(-1)},[]),j=o.useCallback(()=>{const U=y.current;if(!U)return;const J=U.getBoundingClientRect(),ce=Math.max(J.width,Wu[a]),C=Math.min(Math.max(r.length,1)*38+12,260),_=window.innerHeight-J.bottom,ae=_<C&&J.top>_,B=Math.min(Math.max(8,J.left+J.width/2-ce/2),window.innerWidth-ce-8);x({position:"fixed",left:B,top:ae?void 0:J.bottom+6,bottom:ae?window.innerHeight-J.top+6:void 0,width:ce,zIndex:9999})},[r.length,a]),se=o.useCallback(U=>{U.disabled||(n(U.value),Q())},[Q,n]);o.useEffect(()=>A(!0),[]),o.useEffect(()=>{if(!v)return;j();const U=r.findIndex(J=>J.value===e);N(U>=0?U:0)},[v,r,j,e]),o.useEffect(()=>{if(!v)return;function U(J){var C,_;const ce=J.target;!((C=y.current)!=null&&C.contains(ce))&&!((_=L.current)!=null&&_.contains(ce))&&Q()}return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[Q,v]),o.useEffect(()=>{if(v)return window.addEventListener("resize",j),window.addEventListener("scroll",j,!0),()=>{window.removeEventListener("resize",j),window.removeEventListener("scroll",j,!0)}},[v,j]),o.useEffect(()=>{if($<0||!w.current)return;const U=w.current.children[$];U==null||U.scrollIntoView({block:"nearest"})},[$]);function te(U){if(!Z){if(!v){["Enter"," ","ArrowDown","ArrowUp"].includes(U.key)&&(U.preventDefault(),k(!0));return}if(U.key==="Escape"){U.preventDefault(),Q();return}if(U.key==="ArrowDown"){U.preventDefault(),N(J=>Math.min(J+1,r.length-1));return}if(U.key==="ArrowUp"){U.preventDefault(),N(J=>Math.max(J-1,0));return}if(U.key==="Enter"||U.key===" "){U.preventDefault();const J=r[$];J&&se(J)}}}const ee=t.jsx("div",{ref:L,role:"listbox","aria-label":c,className:Vt("overflow-hidden rounded-xl border shadow-xl backdrop-blur-md",b),style:{...T,background:"color-mix(in srgb, var(--bg-card) 92%, transparent)",borderColor:"var(--border)",color:"var(--text-main)"},onClick:D,onMouseDown:D,onPointerDown:D,children:t.jsx("div",{ref:w,className:"max-h-64 overflow-y-auto p-1",style:{scrollbarWidth:"thin",scrollbarColor:"var(--border) transparent",overscrollBehavior:"contain"},children:r.map((U,J)=>{const ce=U.value===e,C=J===$,_={...U.tone?pl[U.tone]:void 0,...U.style};return t.jsxs("button",{type:"button",role:"option","aria-selected":ce,disabled:U.disabled,onMouseEnter:()=>!U.disabled&&N(J),onMouseDown:ae=>{ae.preventDefault(),se(U)},className:Vt("flex w-full items-center gap-2 rounded-lg font-medium text-left transition-colors disabled:cursor-not-allowed disabled:opacity-45",ju[a],ce?U.className:void 0,f),style:{...ce?_:void 0,background:ce?_.background??"color-mix(in srgb, var(--primary) 12%, transparent)":C?"var(--bg-hover)":"transparent",color:ce?_.color??"var(--primary)":"var(--text-main)"},children:[t.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center",children:ce?t.jsx(q.HiCheck,{className:"h-4 w-4"}):null}),t.jsx("span",{className:"min-w-0 flex-1 truncate",children:U.label})]},U.value)})})});return t.jsxs("span",{ref:y,className:Vt("relative inline-flex shrink-0 items-center",u),onKeyDown:te,onClick:D,onPointerDown:D,children:[t.jsx("button",{type:"button",disabled:Z,"aria-label":c,"aria-haspopup":"listbox","aria-expanded":v,title:d,onClick:()=>!Z&&k(U=>!U),className:Vt("inline-flex items-center rounded-full border border-transparent font-medium leading-none outline-none transition-colors hover:border-current focus:border-current disabled:cursor-wait disabled:opacity-70",_u[a],W==null?void 0:W.className,m),style:X,children:t.jsx("span",{className:"min-w-0 truncate",children:(W==null?void 0:W.label)??e})}),t.jsx(q.HiChevronDown,{"aria-hidden":"true",className:Vt("pointer-events-none absolute opacity-70 transition-transform",zu[a],v?"rotate-180":"rotate-0")}),l&&t.jsx("span",{"aria-hidden":"true",className:Vt("absolute -right-1 -top-1 h-2.5 w-2.5 rounded-full border border-current border-t-transparent animate-spin",g)}),v&&h&&ct.createPortal(ee,document.body)]})}function Uu({tabs:e,activeTabId:r,defaultActiveTabId:n,onTabChange:a,ariaLabel:s="Pestanas",variant:l="underline",className:i="",listClassName:c="",panelClassName:d=""}){const u=e.find(v=>!v.disabled)??e[0],m=r??n??(u==null?void 0:u.id),b=e.find(v=>v.id===m)??u,f=v=>{v.disabled||a==null||a(v.id)},g=v=>{const k=e.filter(A=>!A.disabled);if(!k.length||!b)return;const h=k.findIndex(A=>A.id===b.id);(v.key==="ArrowRight"||v.key==="ArrowDown")&&(v.preventDefault(),f(k[(h+1)%k.length])),(v.key==="ArrowLeft"||v.key==="ArrowUp")&&(v.preventDefault(),f(k[(h-1+k.length)%k.length])),v.key==="Home"&&(v.preventDefault(),f(k[0])),v.key==="End"&&(v.preventDefault(),f(k[k.length-1]))};return t.jsxs("div",{className:i,children:[t.jsx("div",{role:"tablist","aria-label":s,onKeyDown:g,className:`flex min-w-0 gap-1 overflow-x-auto ${l==="underline"?"border-b border-[var(--border)]":"rounded-lg border border-[var(--border)] bg-[var(--bg-input)] p-1"} ${c}`,children:e.map(v=>{const k=v.id===(b==null?void 0:b.id);return t.jsxs("button",{type:"button",role:"tab","aria-selected":k,"aria-controls":`${v.id}-panel`,id:`${v.id}-tab`,disabled:v.disabled,tabIndex:k?0:-1,onClick:()=>f(v),className:`inline-flex min-h-8 shrink-0 items-center justify-center gap-1.5 whitespace-nowrap px-2.5 text-sm font-semibold transition-colors focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 ${l==="underline"?"border-b-2":"rounded-md border"}`,style:{color:k?"var(--primary)":"var(--text-muted)",borderColor:k?"var(--primary)":"transparent",background:l==="pills"&&k?"var(--bg-card)":"transparent"},children:[v.icon&&t.jsx("span",{className:"shrink-0",children:v.icon}),t.jsx("span",{children:v.label}),v.badge&&t.jsx("span",{className:"shrink-0",children:v.badge})]},v.id)})}),(b==null?void 0:b.content)!==void 0&&t.jsx("div",{role:"tabpanel",id:`${b.id}-panel`,"aria-labelledby":`${b.id}-tab`,className:`pt-4 ${d}`,children:b.content})]})}function Gt(...e){return e.filter(Boolean).join(" ")}function Vu({steps:e,activeStepId:r,initialStepId:n,completedStepIds:a,defaultCompletedStepIds:s=[],onActiveStepChange:l,onCompletedStepIdsChange:i,onBlockedStep:c,allowBackNavigation:d=!0,showFooter:u=!0,previousLabel:m="Anterior",nextLabel:b="Siguiente",blockedNextLabel:f="Completa este paso",className:g="",headerClassName:v="",contentClassName:k="",footerClassName:h=""}){var K;const A=((K=e[0])==null?void 0:K.id)??"",[$,N]=o.useState(n??A),[T,x]=o.useState(s),y=r??$,L=a??T,w=o.useMemo(()=>new Set(L),[L]),W=Math.max(0,e.findIndex(Y=>Y.id===y)),X=e[W]??e[0],Z=e.length<=1?100:W/(e.length-1)*100,D=Y=>{a||x(Y),i==null||i(Y)},Q=Y=>{const S=e.find(H=>H.id===Y);S&&(r||N(Y),l==null||l(Y,S))},j=Y=>w.has(Y),se=Y=>e.slice(0,Y).find(S=>!S.optional&&!w.has(S.id)),te=Y=>{const S=e[Y];return!S||S.disabled?!1:Y===W||d&&Y<W?!0:!se(Y)},ee=Y=>{const S=e.findIndex(H=>H.id===Y);return S>=0&&te(S)},U=Y=>{const S=e.findIndex(H=>H.id===Y);if(S<0)return!1;if(!te(S)){const H=se(S);return H&&(c==null||c(e[S],H)),!1}return Q(Y),!0},J=(Y=X==null?void 0:X.id)=>{!Y||w.has(Y)||D([...L,Y])},ce=(Y=X==null?void 0:X.id)=>{if(!Y)return;const S=e.findIndex(O=>O.id===Y),H=L.filter(O=>{const re=e.findIndex(z=>z.id===O);return re>=0&&re<S});D(H),S>=0&&W>S&&Q(Y)},C=()=>W<=0?!1:U(e[W-1].id),_=()=>{const Y=e[W+1];return Y?U(Y.id):!1},ae={activeStep:X,activeIndex:W,completedStepIds:L,isCompleted:j,isUnlocked:ee,completeStep:J,uncompleteStep:ce,goToStep:U,goNext:_,goPrevious:C};if(!X)return null;const B=e[W+1],I=W>0,E=B?ee(B.id):!1,oe=typeof X.content=="function"?X.content(ae):X.content;return t.jsxs("section",{className:Gt("overflow-hidden rounded-lg border border-[var(--border)] bg-[var(--bg-card)]",g),children:[t.jsxs("div",{className:Gt("border-b border-[var(--border)] bg-[var(--bg-input)]",v),children:[t.jsx("div",{className:"relative h-1 overflow-hidden bg-[var(--border)]/55",children:t.jsx("div",{className:"h-full rounded-r-full bg-[var(--primary)] transition-[width] duration-500 ease-out",style:{width:`${Z}%`}})}),t.jsx("div",{className:"grid gap-2 p-2",style:{gridTemplateColumns:`repeat(${e.length}, minmax(0, 1fr))`},children:e.map((Y,S)=>{const H=Y.id===X.id,O=j(Y.id),re=te(S),z=se(S);return t.jsxs("button",{type:"button",disabled:!re,"aria-current":H?"step":void 0,"aria-disabled":!re,title:!re&&z?`Completa ${z.title}`:Y.title,onClick:()=>U(Y.id),className:Gt("group relative min-h-16 min-w-0 overflow-hidden rounded-md border p-3 text-left transition-all duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--primary)]/35 disabled:cursor-not-allowed",H&&"border-[var(--primary)] bg-[var(--bg-card)] shadow-sm",O&&!H&&"border-[var(--primary)]/35 bg-[var(--bg-card)]",!H&&!O&&re&&"border-transparent bg-[var(--bg-card)]/45 hover:border-[var(--border)] hover:bg-[var(--bg-card)]",!re&&"border-transparent bg-[var(--bg-card)]/35 opacity-60"),children:[t.jsx("span",{className:Gt("absolute inset-x-0 top-0 h-0.5 origin-left scale-x-0 bg-[var(--primary)] transition-transform duration-300",H&&"scale-x-100")}),t.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:Gt("grid h-7 w-7 shrink-0 place-items-center rounded-full border text-xs font-bold transition-all duration-200",H&&"border-[var(--primary)] bg-[var(--primary)] text-[var(--primary-fg)]",O&&!H&&"border-[var(--primary)] bg-[var(--primary)]/12 text-[var(--primary)]",!O&&!H&&re&&"border-[var(--border)] text-[var(--text-muted)]",!re&&"border-[var(--border)] text-[var(--text-muted)]"),children:O?t.jsx(q.HiCheck,{className:"h-4 w-4"}):re?S+1:t.jsx(q.HiLockClosed,{className:"h-3.5 w-3.5"})}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsxs("span",{className:Gt("block truncate text-xs font-semibold transition-colors duration-200",H?"text-[var(--text-main)]":"text-[var(--text-secondary)]"),children:[S+1,". ",Y.title]}),Y.description&&t.jsx("span",{className:"mt-1 block truncate text-[11px] text-[var(--text-muted)]",children:Y.description})]}),Y.badge&&t.jsx("span",{className:"shrink-0",children:Y.badge})]})]},Y.id)})})]}),t.jsx("div",{className:Gt("min-h-72 animate-[stepWizardIn_220ms_ease-out] p-5",k),children:oe},X.id),u&&t.jsxs("div",{className:Gt("flex flex-wrap items-center justify-between gap-3 border-t border-[var(--border)] bg-[var(--bg-input)] px-4 py-3",h),children:[t.jsx(Ue,{variant:"secondary",height:38,padding:"0 14px",icon:t.jsx(q.HiChevronLeft,{}),disabled:!I,onClick:C,children:m}),t.jsxs("div",{className:"flex items-center gap-3 text-xs text-[var(--text-muted)]",children:[t.jsxs("span",{children:["Paso ",W+1," de ",e.length]}),t.jsx("span",{className:"h-1 w-1 rounded-full bg-[var(--border)]"}),t.jsxs("span",{children:[L.length," completados"]})]}),t.jsx(Ue,{height:38,padding:"0 14px",icon:t.jsx(q.HiChevronRight,{}),disabled:!B||!E,onClick:_,children:B&&!E?f:b})]})]})}const Yu={sm:"px-2.5 py-1.5 text-xs leading-5",md:"px-2.5 py-1.5 text-sm leading-5",lg:"px-3 py-2 text-sm leading-6"};function Xu(e,r){if(e){if(typeof e=="function"){e(r);return}e.current=r}}function Ku(e){const r=getComputedStyle(e),n=Number.parseFloat(r.lineHeight),a=Number.parseFloat(r.paddingTop)+Number.parseFloat(r.paddingBottom),s=Number.parseFloat(r.borderTopWidth)+Number.parseFloat(r.borderBottomWidth);return{lineHeight:Number.isFinite(n)?n:20,paddingY:Number.isFinite(a)?a:12,borderY:Number.isFinite(s)?s:2}}function hl(e,r){const{lineHeight:n,paddingY:a,borderY:s}=Ku(e);return Math.ceil(r*n+a+s)}const gl=o.forwardRef(function({className:r="",size:n="md",status:a="default",maxHeight:s,maxRows:l,minRows:i=1,style:c,value:d,defaultValue:u,onInput:m,...b},f){const g=o.useRef(null),v=a==="error"?"var(--danger)":a==="success"?"#16a34a":"var(--border)",k=o.useCallback(()=>{const h=g.current;if(!h)return;h.style.height="auto";const A=h.scrollHeight,$=hl(h,i),N=s??(l!==void 0?hl(h,l):void 0),T=N!==void 0?Math.min(Math.max(A,$),N):Math.max(A,$);h.style.height=`${T}px`,h.style.overflowY=N!==void 0&&A>N?"auto":"hidden"},[s,l,i]);return o.useLayoutEffect(()=>{k()},[k,d,u]),o.useEffect(()=>{const h=g.current;if(!h||typeof ResizeObserver>"u")return;const A=new ResizeObserver(()=>k());return A.observe(h),()=>A.disconnect()},[k]),t.jsx("textarea",{...b,ref:h=>{g.current=h,Xu(f,h)},rows:i,value:d,defaultValue:u,"aria-invalid":a==="error"||b["aria-invalid"],onInput:h=>{k(),m==null||m(h)},style:{...c,borderColor:v,minHeight:void 0},className:`w-full resize-none overflow-hidden rounded-lg border bg-[var(--bg-input)] text-[var(--text-main)] outline-none placeholder:text-[var(--text-muted)] transition-colors focus:border-[var(--primary)] disabled:cursor-not-allowed disabled:opacity-60 ${Yu[n]} ${r}`})});function Gu({label:e,containerClassName:r="",helperText:n,helperDisplay:a,error:s,labelAction:l,required:i,className:c="",status:d,...u}){return t.jsx(In,{label:e,required:i,helperText:n,helperDisplay:a,error:s,labelAction:l,className:r,children:t.jsx(gl,{...u,required:i,status:s?"error":d,className:`w-full ${c}`})})}const Zu={sm:"min-h-20 px-2.5 py-1.5 text-xs leading-5",md:"min-h-24 px-2.5 py-2 text-sm leading-5",lg:"min-h-32 px-3 py-2.5 text-sm leading-6"},Qu={none:"resize-none",vertical:"resize-y",horizontal:"resize-x",both:"resize"};function Ju(e,r){if(e){if(typeof e=="function"){e(r);return}e.current=r}}function Ru(e,r){return e!==void 0?String(e).length:r!==void 0?String(r).length:0}const vl=o.forwardRef(function({className:r="",wrapperClassName:n="",size:a="md",resize:s="vertical",autoResize:l=!1,minRows:i,maxRows:c,showCount:d=!1,maxCount:u,status:m="default",icon:b,action:f,style:g,value:v,defaultValue:k,maxLength:h,onInput:A,...$},N){const T=o.useRef(null),x=Ru(v,k),y=u??h,L=!!(b||f||d),w=m==="error"?"var(--danger)":m==="success"?"#16a34a":"var(--border)",W={...g??{},...i?{minHeight:`${i*24+18}px`}:null,...c?{maxHeight:`${c*24+18}px`}:null},X=()=>{const D=T.current;!D||!l||(D.style.height="auto",D.style.height=`${D.scrollHeight}px`)};o.useEffect(X,[l,v]);const Z=t.jsx("textarea",{...$,ref:D=>{T.current=D,Ju(N,D)},value:v,defaultValue:k,maxLength:h,"aria-invalid":m==="error"||$["aria-invalid"],onInput:D=>{X(),A==null||A(D)},style:{...W,borderColor:w},className:`w-full rounded-lg border bg-[var(--bg-input)] text-[var(--text-main)] outline-none placeholder:text-[var(--text-muted)] transition-colors focus:border-[var(--primary)] disabled:cursor-not-allowed disabled:opacity-60 ${Zu[a]} ${Qu[l?"none":s]} ${b?"pl-8":""} ${f?"pr-10":""} ${r}`});return L?t.jsxs("span",{className:`relative block ${n}`,children:[b&&t.jsx("span",{className:"pointer-events-none absolute left-2.5 top-2.5 flex h-4 w-4 items-center justify-center text-[var(--text-muted)]",children:b}),Z,f&&t.jsx("span",{className:"absolute right-2 top-2 flex items-center justify-center",children:f}),d&&t.jsxs("span",{className:"absolute bottom-1.5 right-2 rounded bg-[var(--bg-input)] px-1.5 text-[10px] font-semibold text-[var(--text-muted)]",children:[x,y?`/${y}`:""]})]}):Z});function ef({label:e,containerClassName:r="",helperText:n,helperDisplay:a,error:s,labelAction:l,required:i,className:c="",status:d,...u}){return t.jsx(In,{label:e,required:i,helperText:n,helperDisplay:a,error:s,labelAction:l,className:r,children:t.jsx(vl,{...u,required:i,status:s?"error":d,className:`w-full ${c}`})})}const yl=[{bg:"#dbeafe",text:"#1e40af",border:"#bfdbfe"},{bg:"#dcfce7",text:"#166534",border:"#bbf7d0"},{bg:"#fce7f3",text:"#9d174d",border:"#fbcfe8"},{bg:"#fef9c3",text:"#854d0e",border:"#fef08a"},{bg:"#ede9fe",text:"#5b21b6",border:"#ddd6fe"},{bg:"#ffedd5",text:"#9a3412",border:"#fed7aa"},{bg:"#cffafe",text:"#155e75",border:"#a5f3fc"},{bg:"#f0fdf4",text:"#14532d",border:"#bbf7d0"}];function tf(e){return yl[e%yl.length]}let rf=0;function bo(){return++rf}function xl(e,r){return r?r instanceof RegExp?r.test(e):r(e):!0}function nf(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function af(e,r){const n=r.filter(Boolean);if(n.length===0)return[e.trim()].filter(Boolean);const a=new RegExp(`${n.map(s=>nf(s)).join("|")}|\\r?\\n`,"g");return e.split(a).map(s=>s.trim()).filter(Boolean)}function of({value:e,defaultValue:r,onChange:n,placeholder:a="Escribe y presiona Enter…",disabled:s=!1,className:l="",delimiters:i=[","],maxTags:c,allowDuplicates:d=!1,validate:u,label:m,helperText:b,helperDisplay:f="inline",error:g,required:v=!1}){const k=e!==void 0,h=!!g,A=!!b&&f==="tooltip"&&!h,[$,N]=o.useState(()=>(r??[]).map((O,re)=>({id:bo(),value:O.trim(),colorIndex:re})));o.useEffect(()=>{k&&N(O=>{const re=e??[],z=new Map(O.map(de=>[de.value,de]));return re.map((de,he)=>z.get(de)??{id:bo(),value:de,colorIndex:he})})},[k,e]);const T=$,[x,y]=o.useState(""),[L,w]=o.useState(null),[W,X]=o.useState(""),[Z,D]=o.useState(!1),[Q,j]=o.useState(!1),se=o.useRef(null),te=o.useRef(null),ee=o.useRef(null);function U(){j(!0),setTimeout(()=>j(!1),400)}function J(O){N(O),n==null||n(O.map(re=>re.value))}function ce(O){let re=T,z=!1,de=!1;for(const he of O){const ie=he.trim();if(ie){if(c!==void 0&&re.length>=c){de=!0;break}if(!d&&re.some(ge=>ge.value.toLowerCase()===ie.toLowerCase())){de=!0;continue}if(!xl(ie,u)){de=!0;continue}re=[...re,{id:bo(),value:ie,colorIndex:re.length}],z=!0}}return z&&J(re),de&&U(),z}function C(O){return ce([O])}function _(O){const re=T.filter(z=>z.id!==O);J(re.map((z,de)=>({...z,colorIndex:de})))}function ae(O,re){const z=re.trim();if(w(null),X(""),!z){_(O);return}if(!(!d&&T.some(de=>de.id!==O&&de.value.toLowerCase()===z.toLowerCase()))){if(!xl(z,u)){U();return}J(T.map(de=>de.id===O?{...de,value:z}:de))}}function B(O){s||(w(O.id),X(O.value),setTimeout(()=>{var re;return(re=te.current)==null?void 0:re.select()},0))}function I(O){if(O.key==="Enter"||i.includes(O.key)){O.preventDefault(),C(x)&&y("");return}if(O.key==="Backspace"&&x===""&&T.length>0){O.preventDefault();const re=T[T.length-1];_(re.id)}}function E(O,re){if(O.key==="Enter"){O.preventDefault(),ae(re,W),setTimeout(()=>{var z;return(z=se.current)==null?void 0:z.focus()},0);return}O.key==="Escape"&&(O.preventDefault(),w(null),X(""),setTimeout(()=>{var z;return(z=se.current)==null?void 0:z.focus()},0))}function oe(){var O;s||(O=se.current)==null||O.focus()}function K(O){if(s)return;const re=O.clipboardData.getData("text");if(!re||!(i.some(ie=>ie&&re.includes(ie))||re.includes(`
31
+ `)))return;O.preventDefault();const de=af(re,i);ce(de)&&y("")}function Y(){const O=x.trim();O&&C(O)&&y("")}const S=h?"var(--danger)":Z?"var(--primary)":"var(--border)",H=c!==void 0&&T.length>=c;return t.jsxs("div",{className:`flex flex-col gap-2 ${l}`,children:[(m||v||A)&&t.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-semibold uppercase text-[var(--text-muted)]",children:[m&&t.jsx("span",{children:m}),v&&t.jsx("span",{className:"text-[var(--danger)]",children:"*"}),A?t.jsx(xr,{content:b}):null]}),t.jsxs("div",{ref:ee,onClick:oe,onFocus:()=>D(!0),onBlur:O=>{var re;(re=ee.current)!=null&&re.contains(O.relatedTarget)||(D(!1),L!==null&&ae(L,W),L===null&&Y())},style:{borderColor:S},className:`
32
32
  flex min-h-10 flex-wrap items-center gap-1.5 rounded-lg border
33
33
  bg-[var(--bg-input)] px-2.5 py-2 transition-colors
34
34
  ${s?"cursor-not-allowed opacity-60":"cursor-text"}
@@ -41,7 +41,7 @@ ${ee}`,ne=new Blob(["\uFEFF"+F],{type:"text/csv;charset=utf-8;"}),be=URL.createO
41
41
  60% { transform: translateX(-3px); }
42
42
  80% { transform: translateX(3px); }
43
43
  }
44
- `}),x.map(I=>{const te=Ku(I.colorIndex);return A===I.id?t.jsx("input",{ref:re,value:U,disabled:s,onChange:P=>K(P.target.value),onKeyDown:P=>$(P,I.id),onBlur:()=>ae(I.id,U),className:"min-w-[4rem] rounded border border-[var(--primary)] bg-transparent px-1 py-0.5 text-sm text-[var(--text-main)] outline-none",style:{width:`${Math.max(U.length+2,6)}ch`}},I.id):t.jsxs("span",{className:"inline-flex max-w-[240px] items-center gap-1 rounded-md px-2 py-0.5 text-xs font-medium",style:{backgroundColor:te.bg,color:te.text,border:`1px solid ${te.border}`},children:[t.jsx("span",{className:"truncate",children:I.value}),t.jsx("button",{type:"button","aria-label":`Editar "${I.value}"`,disabled:s,tabIndex:-1,onClick:P=>{P.stopPropagation(),H(I)},className:"flex h-4 w-4 flex-shrink-0 items-center justify-center rounded opacity-60 transition-opacity hover:opacity-100 focus:outline-none disabled:pointer-events-none",children:t.jsx(q.HiPencil,{className:"h-3 w-3"})}),t.jsx("button",{type:"button","aria-label":`Eliminar "${I.value}"`,disabled:s,tabIndex:-1,onClick:P=>{P.stopPropagation(),W(I.id)},className:"flex h-4 w-4 flex-shrink-0 items-center justify-center rounded opacity-60 transition-opacity hover:opacity-100 focus:outline-none disabled:pointer-events-none",children:t.jsx(q.HiXMark,{className:"h-3.5 w-3.5"})})]},I.id)}),!O&&t.jsx("input",{ref:se,value:w,disabled:s,placeholder:x.length===0?a:"",onChange:I=>N(I.target.value),onKeyDown:D,onPaste:G,className:"min-w-[8rem] flex-1 bg-transparent text-sm text-[var(--text-main)] outline-none placeholder:text-[var(--text-muted)] disabled:cursor-not-allowed"})]}),t.jsx(wr,{error:g,helperText:b,helperDisplay:f})]})}const Ru=/^(\d{1,2}):(\d{2})(?::(\d{2}))?$/;function Ze(e){return String(e).padStart(2,"0")}function io(e,r=Mr()){const n=e.trim();if(!n)return r;const a=n.match(Ru);if(!a)return r;const s=Number(a[1]),l=Number(a[2]),i=a[3]?Number(a[3]):0;return!Number.isFinite(s)||!Number.isFinite(l)||!Number.isFinite(i)||s<0||s>23||l<0||l>59||i<0||i>59?r:{hour24:s,minute:l,second:i}}function rn(e,r=!0){const n=`${Ze(e.hour24)}:${Ze(e.minute)}`;return r?`${n}:${Ze(e.second)}`:n}function Un(e){const r=e.hour24>=12?"PM":"AM";return{hour12:e.hour24%12===0?12:e.hour24%12,minute:e.minute,second:e.second,meridiem:r}}function nn(e){let n=Math.min(12,Math.max(1,e.hour12))%12;return e.meridiem==="PM"&&(n+=12),{hour24:n,minute:Math.min(59,Math.max(0,e.minute)),second:Math.min(59,Math.max(0,e.second))}}function ef(e,r){const n=(r==null?void 0:r.use12Hour)??!1,a=(r==null?void 0:r.showSeconds)??!0,s=io(e);if(n){const l=Un(s),i=`${l.hour12}:${Ze(l.minute)}`;return`${a?`${i}:${Ze(l.second)}`:i} ${l.meridiem}`}return rn(s,a)}function Mr(){const e=new Date;return{hour24:e.getHours(),minute:e.getMinutes(),second:e.getSeconds()}}function tf(e=!0){return rn(Mr(),e)}function co(e,r){const n=[];for(let a=e;a<=r;a+=1)n.push(a);return n}const xt=36,uo=5,hl=Math.floor(uo/2),rf=52,nf=48,_t=18;function gl(e){return e*xt}function vl(e){return Math.round(e/xt)}function af(e){return e.use12Hour??e.hour12??!1}function Vn({values:e,selected:r,onSelect:n,syncEpochRef:a,forceSyncAt:s=0,width:l=rf,label:i,maxNumeric:c=59,isMeridiem:d=!1,isFocused:u=!1,onFocus:m,onAdvance:b,onBack:f,setColumnRef:g}){const v=o.useRef(null),k=o.useRef(null),h=o.useRef(null),C=o.useRef(""),M=o.useRef(0),y=o.useRef(!1),[x,w]=o.useState(r),[N,A]=o.useState(""),T=o.useCallback(H=>{C.current=H,A(H)},[]),U=o.useMemo(()=>[...Array(hl).fill(""),...e,...Array(hl).fill("")],[e]),K=o.useCallback(()=>{const H=v.current;if(!H)return r;const D=vl(H.scrollTop),$=Math.min(Math.max(D,0),e.length-1);return e[$]??r},[r,e]),Z=o.useCallback((H,D=!0)=>{const $=Math.min(Math.max(H,0),e.length-1),oe=e[$],G=v.current;!G||!oe||(k.current&&(window.clearTimeout(k.current),k.current=null),y.current=!0,M.current=$,G.scrollTop=gl($),w(oe),D&&oe!==r&&n(oe))},[n,r,e]);o.useLayoutEffect(()=>{k.current&&(window.clearTimeout(k.current),k.current=null),h.current&&(window.clearTimeout(h.current),h.current=null),T(""),w(r);const H=e.indexOf(r);if(H>=0&&(M.current=H),H<0||!v.current)return;const D=gl(H);v.current.scrollTop!==D&&(v.current.scrollTop=D)},[s,r,T,e]);const L=o.useCallback(()=>{h.current&&(window.clearTimeout(h.current),h.current=null)},[]),Q=o.useCallback((H,D=!1)=>{L(),T("");const $=Number(H);if(!Number.isFinite($))return;const oe=Math.min(c,Math.max(0,$));let G=Ze(oe),X=e.indexOf(G);if(X<0){const S=Math.min(e.length-1,Math.max(0,oe-(c===12?1:0)));G=e[S]??G,X=e.indexOf(G)}X>=0&&Z(X),D&&(b==null||b())},[L,c,b,Z,T,e]),z=o.useCallback(H=>{const D=Math.floor(c/10),$=C.current;if($===""){if(H>D){Q(String(H),!0);return}const G=String(H);T(G),h.current=window.setTimeout(()=>{Q(C.current,!0)},1200);return}L();const oe=+`${$}${H}`;oe<=c?Q(String(oe),!0):Q(String(H),!0)},[L,Q,c,T]),se=o.useCallback(H=>{L(),T(""),Z(M.current+H)},[L,Z,T]),re=H=>{if(d){H.key==="a"||H.key==="A"?(H.preventDefault(),n("AM"),b==null||b()):H.key==="p"||H.key==="P"?(H.preventDefault(),n("PM"),b==null||b()):H.key==="ArrowUp"||H.key==="ArrowDown"?(H.preventDefault(),n(r==="AM"?"PM":"AM")):H.key==="Tab"&&(H.preventDefault(),H.shiftKey?f==null||f():b==null||b());return}if(/^\d$/.test(H.key)){H.preventDefault(),z(Number(H.key));return}H.key==="ArrowUp"?(H.preventDefault(),se(-1)):H.key==="ArrowDown"?(H.preventDefault(),se(1)):H.key==="Tab"&&(H.preventDefault(),L(),C.current!==""&&Q(C.current,!1),H.shiftKey?f==null||f():b==null||b())},R=o.useCallback(()=>{const H=a.current,D=v.current;D&&H===a.current&&Z(vl(D.scrollTop))},[Z,a]),V=()=>{if(C.current!=="")return;if(y.current){y.current=!1;const D=K();w(D);const $=e.indexOf(D);$>=0&&(M.current=$);return}w(K()),k.current&&window.clearTimeout(k.current);const H=a.current;k.current=window.setTimeout(()=>{H===a.current&&R()},100)},B="absolute left-0 right-0 z-40 flex items-center justify-center border-0 bg-transparent p-0 transition-opacity duration-150 hover:opacity-80 focus:outline-none",le=xt*uo,j=le+_t*2,W=N!==""?N:null,ae=W!==null;return t.jsxs("div",{ref:g,role:"spinbutton",tabIndex:u?0:-1,"aria-label":i,"aria-valuetext":W??r,"aria-valuenow":d?void 0:Number(r),onFocus:m,onMouseDown:()=>m==null?void 0:m(),onKeyDown:re,onBlur:()=>{L(),C.current!==""&&Q(C.current,!1)},className:"relative shrink-0 rounded-lg outline-none",style:{width:l,height:j,boxShadow:u?"0 0 0 2px color-mix(in srgb, var(--primary) 35%, transparent)":"none"},children:[t.jsx("button",{type:"button","aria-label":"Valor anterior",className:B,style:{top:0,height:_t,color:"var(--text-muted)",opacity:.35},onClick:()=>se(-1),children:t.jsx(q.HiChevronUp,{className:"h-3.5 w-3.5"})}),t.jsx("div",{ref:v,className:"absolute inset-x-0 overflow-y-auto [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden",style:{top:_t,height:le,scrollSnapType:"y mandatory",scrollBehavior:"auto"},onScroll:V,onMouseUp:R,onTouchEnd:R,children:U.map((H,D)=>{const $=H!==""&&H===x;return t.jsx("button",{type:"button",tabIndex:-1,disabled:!H,onClick:()=>{if(!H)return;const oe=e.indexOf(H);oe>=0&&Z(oe)},className:"flex w-full items-center justify-center tabular-nums leading-none disabled:cursor-default",style:{height:xt,scrollSnapAlign:"center",color:$?"var(--text-main)":"var(--text-muted)",fontSize:$?16:14,fontWeight:$?600:400,opacity:H?ae?$?0:.35:$?1:.35:0},children:H},`wheel-${D}-${H}`)})}),W!==null?t.jsx("div",{className:"pointer-events-none absolute inset-x-0 z-50 flex items-center justify-center tabular-nums font-semibold leading-none",style:{top:_t+le/2-xt/2,height:xt,color:"var(--text-main)",fontSize:16,background:"var(--bg-card)"},children:W}):null,t.jsx("button",{type:"button","aria-label":"Valor siguiente",className:B,style:{bottom:0,height:_t,color:"var(--text-muted)",opacity:.35},onClick:()=>se(1),children:t.jsx(q.HiChevronDown,{className:"h-3.5 w-3.5"})})]})}function yl(){return t.jsx("span",{className:"flex shrink-0 items-center justify-center self-center text-base font-medium tabular-nums leading-none",style:{color:"var(--text-muted)",height:xt,width:14,opacity:.45},"aria-hidden":!0,children:":"})}function xl({value:e,onChange:r,use12Hour:n,hour12:a,showSeconds:s=!1,title:l="Seleccionar hora",variant:i="panel",onCancel:c,onConfirm:d,className:u=""}){const m=i==="popover",b=m||!d,f=af({use12Hour:n,hour12:a}),g=o.useRef(e),v=io(e,Mr()),k=Un(v),[h,C]=o.useState(Ze(f?k.hour12:v.hour24)),[M,y]=o.useState(Ze(v.minute)),[x,w]=o.useState(Ze(v.second)),[N,A]=o.useState(k.meridiem),[T,U]=o.useState(0),K=o.useRef(0),Z=o.useRef(!1),L=o.useRef({hour:null,minute:null,second:null,meridiem:null}),[Q,z]=o.useState("hour"),se=o.useMemo(()=>{const ie=["hour","minute"];return s&&ie.push("second"),f&&ie.push("meridiem"),ie},[f,s]),re=o.useCallback(ie=>{z(ge=>{const Te=se.indexOf(ge);return se[(Te+ie+se.length)%se.length]})},[se]);o.useEffect(()=>{var ie;(ie=L.current[Q])==null||ie.focus()},[Q]),o.useEffect(()=>{var ie;z("hour"),(ie=L.current.hour)==null||ie.focus()},[]),o.useEffect(()=>{if(e===g.current)return;g.current=e;const ie=io(e,Mr()),ge=Un(ie);C(Ze(f?ge.hour12:ie.hour24)),y(Ze(ie.minute)),w(Ze(ie.second)),A(ge.meridiem)},[f,e]);const R=o.useMemo(()=>(f?co(1,12):co(0,23)).map(ie=>Ze(ie)),[f]),V=o.useMemo(()=>co(0,59).map(ie=>Ze(ie)),[]),B=V,le=o.useMemo(()=>["AM","PM"],[]),j=o.useCallback(()=>f?nn({hour12:Number(h),minute:Number(M),second:Number(x),meridiem:N}):{hour24:Number(h),minute:Number(M),second:Number(x)},[h,f,N,M,x]),W=o.useCallback(ie=>{if(Z.current)return;const ge=rn(ie,s);g.current=ge,r(ge)},[r,s]),ae=o.useCallback(()=>{W(j())},[j,W]),H=ie=>{C(ie),b&&W(f?nn({hour12:Number(ie),minute:Number(M),second:Number(x),meridiem:N}):{hour24:Number(ie),minute:Number(M),second:Number(x)})},D=ie=>{y(ie),b&&W(f?nn({hour12:Number(h),minute:Number(ie),second:Number(x),meridiem:N}):{hour24:Number(h),minute:Number(ie),second:Number(x)})},$=ie=>{w(ie),b&&W(f?nn({hour12:Number(h),minute:Number(M),second:Number(ie),meridiem:N}):{hour24:Number(h),minute:Number(M),second:Number(ie)})},oe=ie=>{A(ie),b&&W(nn({hour12:Number(h),minute:Number(M),second:Number(x),meridiem:ie}))},G=o.useCallback(()=>(K.current+=1,U(K.current),K.current),[]),X=o.useCallback(ie=>{const ge=Un(ie),Te=rn(ie,s);g.current=Te,C(Ze(f?ge.hour12:ie.hour24)),y(Ze(ie.minute)),w(Ze(ie.second)),A(ge.meridiem),r(Te)},[f,r,s]),S=()=>{Z.current=!0,G(),X(Mr()),queueMicrotask(()=>{const ie=Mr();rn(ie,s)!==g.current&&(G(),X(ie)),Z.current=!1})},O=()=>{ae(),d==null||d()},I=xt*uo,te=I+_t*2,P=_t+I/2-xt/2,ce=t.jsx("div",{className:"relative px-4 py-2",children:t.jsxs("div",{className:"relative mx-auto",style:{height:te,maxWidth:"100%"},children:[t.jsx("div",{className:"pointer-events-none absolute inset-x-1 z-10 rounded-xl",style:{top:P,height:xt,background:"color-mix(in srgb, var(--primary) 10%, var(--bg-input))",border:"1px solid color-mix(in srgb, var(--primary) 22%, transparent)"}}),t.jsx("div",{className:"pointer-events-none absolute inset-x-0 z-20",style:{top:_t,height:xt*1.35,background:"linear-gradient(to bottom, var(--bg-card) 40%, transparent 100%)"}}),t.jsx("div",{className:"pointer-events-none absolute inset-x-0 z-20",style:{bottom:_t,height:xt*1.35,background:"linear-gradient(to top, var(--bg-card) 40%, transparent 100%)"}}),t.jsxs("div",{className:"relative z-30 flex h-full items-center justify-center gap-1",children:[t.jsx(Vn,{syncEpochRef:K,forceSyncAt:T,values:R,selected:h,onSelect:H,label:"Horas",maxNumeric:f?12:23,isFocused:Q==="hour",onFocus:()=>z("hour"),onAdvance:()=>re(1),onBack:()=>re(-1),setColumnRef:ie=>{L.current.hour=ie}}),t.jsx(yl,{}),t.jsx(Vn,{syncEpochRef:K,forceSyncAt:T,values:V,selected:M,onSelect:D,label:"Minutos",maxNumeric:59,isFocused:Q==="minute",onFocus:()=>z("minute"),onAdvance:()=>re(1),onBack:()=>re(-1),setColumnRef:ie=>{L.current.minute=ie}}),s?t.jsxs(t.Fragment,{children:[t.jsx(yl,{}),t.jsx(Vn,{syncEpochRef:K,forceSyncAt:T,values:B,selected:x,onSelect:$,label:"Segundos",maxNumeric:59,isFocused:Q==="second",onFocus:()=>z("second"),onAdvance:()=>re(1),onBack:()=>re(-1),setColumnRef:ie=>{L.current.second=ie}})]}):null,f?t.jsx("div",{className:"ml-3 shrink-0 pl-1",children:t.jsx(Vn,{syncEpochRef:K,forceSyncAt:T,values:le,selected:N,onSelect:ie=>oe(ie),width:nf,label:"AM o PM",isMeridiem:!0,isFocused:Q==="meridiem",onFocus:()=>z("meridiem"),onAdvance:()=>re(1),onBack:()=>re(-1),setColumnRef:ie=>{L.current.meridiem=ie}})}):null]})]})}),he=t.jsxs("div",{className:`flex items-center ${m?"justify-center px-3 py-2":"justify-between gap-2 px-3 py-2.5"}`,style:{borderTop:m?"none":"1px solid color-mix(in srgb, var(--border) 80%, transparent)"},children:[t.jsx(Ue,{variant:"ghost",size:"sm",onClick:S,className:m?"text-xs":void 0,children:"Ahora"}),!m&&(c||d)?t.jsxs("div",{className:"flex items-center gap-2",children:[c?t.jsx(Ue,{variant:"ghost",size:"sm",onClick:c,children:"Cancelar"}):null,d?t.jsx(Ue,{variant:"primary",size:"sm",onClick:O,children:"Listo"}):null]}):null]});return t.jsxs("div",{className:`overflow-hidden ${u}`,style:{borderRadius:m?12:14,border:m?"1px solid color-mix(in srgb, var(--border) 85%, transparent)":"1px solid var(--border)",background:"var(--bg-card)",boxShadow:m?"0 12px 40px rgba(15, 23, 42, 0.14), 0 2px 8px rgba(15, 23, 42, 0.06)":"0 1px 3px rgba(15, 23, 42, 0.06)",minWidth:f?s?300:260:s?252:212},children:[!m&&l?t.jsx("div",{className:"border-b px-3 py-2.5",style:{borderColor:"color-mix(in srgb, var(--border) 80%, transparent)"},children:t.jsx("h3",{className:"text-sm font-semibold",style:{color:"var(--text-main)"},children:l})}):null,ce,he]})}function of(e){return e.use12Hour??e.hour12??!1}function sf({label:e,value:r,onChange:n,use12Hour:a,hour12:s,showSeconds:l=!1,title:i="Seleccionar hora",placeholder:c="Seleccionar hora",disabled:d=!1,displayMode:u="popover",required:m,error:b,helperText:f,helperDisplay:g,className:v,contentClassName:k,className:h=""}){const C=u==="popover",[M,y]=o.useState(!1),x=o.useRef(null),[w,N]=o.useState({horizontal:"left",vertical:"bottom"}),A=of({use12Hour:a,hour12:s}),T=o.useMemo(()=>r?ef(r,{use12Hour:A,showSeconds:l}):"",[A,l,r]);o.useEffect(()=>{if(!C||!M||!x.current)return;const Z=x.current.getBoundingClientRect(),L=8,Q=A?l?300:260:l?252:212,z=276,se=Z.left+Q>window.innerWidth-L,re=Z.right-Q>=L,R=Z.bottom+8+z>window.innerHeight-L,V=Z.top-8-z>=L;N({horizontal:se&&re?"right":"left",vertical:R&&V?"top":"bottom"})},[A,C,M,l]),o.useEffect(()=>{if(!C||!M)return;function Z(Q){x.current&&(x.current.contains(Q.target)||y(!1))}function L(Q){Q.key==="Escape"&&y(!1)}return document.addEventListener("mousedown",Z),document.addEventListener("keydown",L),()=>{document.removeEventListener("mousedown",Z),document.removeEventListener("keydown",L)}},[C,M]);const U=t.jsxs("button",{type:"button",disabled:d,onClick:()=>{d||y(Z=>!Z)},className:`flex h-10 w-full items-center justify-between gap-2 rounded-lg border px-2.5 text-sm transition-all duration-150 focus:outline-none disabled:cursor-not-allowed disabled:opacity-60 ${h}`,style:{background:"var(--bg-input)",borderColor:b?"var(--danger)":M?"var(--primary)":"var(--border)",color:T?"var(--text-main)":"var(--text-muted)",boxShadow:M?"0 0 0 3px color-mix(in srgb, var(--primary) 14%, transparent)":"none"},children:[t.jsxs("span",{className:"inline-flex min-w-0 items-center gap-2",children:[t.jsx(q.HiClock,{className:"h-4 w-4 shrink-0 text-[var(--text-muted)]"}),t.jsx("span",{className:"truncate",children:T||c})]}),C?t.jsx(q.HiChevronDown,{className:`h-4 w-4 shrink-0 text-[var(--text-muted)] transition-transform duration-150 ${M?"rotate-180":""}`}):null]}),K=t.jsx(xl,{variant:C?"popover":"panel",value:r||tf(l),onChange:n,use12Hour:A,showSeconds:l,title:i,onClose:()=>y(!1)});return t.jsx($n,{label:e,required:m,error:b,helperText:f,helperDisplay:g,className:v,contentClassName:k,children:C?t.jsxs("div",{ref:x,className:"relative w-full",children:[U,M?t.jsx("div",{className:"absolute z-50",style:{...w.horizontal==="left"?{left:0}:{right:0},...w.vertical==="bottom"?{top:"calc(100% + 6px)"}:{bottom:"calc(100% + 6px)"}},children:K}):null]}):t.jsxs("div",{className:"space-y-2",children:[U,M?K:null]})})}const lf={xs:{width:28,height:16,thumb:12,padding:2},sm:{width:36,height:20,thumb:16,padding:2}};function cf({checked:e,disabled:r,onCheckedChange:n,size:a="sm",className:s="",...l}){const i=lf[a],c=e?i.width-i.thumb-i.padding*2:0;return t.jsx("button",{...l,type:"button",role:"switch","aria-checked":e,disabled:r,onClick:()=>!r&&n(!e),className:`relative inline-flex shrink-0 items-center rounded-full transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--primary)]/50 disabled:cursor-not-allowed disabled:opacity-50 ${s}`,style:{width:i.width,height:i.height,background:e?"color-mix(in srgb, var(--primary) 85%, transparent)":"var(--bg-input)",border:e?"1px solid color-mix(in srgb, var(--primary) 55%, transparent)":"1px solid var(--border)"},children:t.jsx("span",{className:"absolute inline-block rounded-full transition-transform",style:{width:i.thumb,height:i.thumb,left:i.padding,top:"50%",transform:`translate(${c}px, -50%)`,background:e?"var(--primary-fg)":"var(--text-muted)"}})})}const wl=[".sidebar-scroll",".app-scroll",".showcase-nav-scroll","[data-overlay-scroll='true']"].join(","),df=[":scope > [data-overlayscrollbars-contents]",":scope > .sidebar-scroll-body",":scope > .showcase-nav-scroll-body",":scope > .app-scroll-body"].join(", ");function uf(e){if(!(e instanceof HTMLElement)||e.dataset.overlayScroll==="false"||e.matches("[data-overlayscrollbars]")||e.closest("[data-overlayscrollbars]")||e.matches("textarea,input,select,[contenteditable='true']"))return!1;const r=window.getComputedStyle(e);return!(![r.overflow,r.overflowX,r.overflowY].join(" ").match(/auto|scroll/)||e.clientWidth===0&&e.clientHeight===0)}function Nl(e){return e.classList.contains("sidebar-scroll")||e.classList.contains("showcase-nav-scroll")}function kl(e){Nl(e)&&e.querySelectorAll(".os-scrollbar-horizontal").forEach(r=>{r.style.display="none",r.style.height="0",r.style.pointerEvents="none"})}function ff(e){const r=e.querySelector(df);return r instanceof HTMLElement?r:null}function Sl(){return o.useEffect(()=>{const e=new WeakMap;let r=0;const n=()=>{r=0,document.querySelectorAll(wl).forEach(l=>{if(!(l instanceof HTMLElement))return;if(ka.OverlayScrollbars(l)){kl(l);return}if(!uf(l))return;const c={overflow:Nl(l)?{x:"hidden",y:"scroll"}:void 0,scrollbars:{autoHide:"leave",autoHideDelay:180}},d=ff(l),u=d?ka.OverlayScrollbars({target:l,elements:{viewport:d}},c):ka.OverlayScrollbars(l,c);kl(l),e.set(l,u)})},a=()=>{r||(r=window.requestAnimationFrame(n))};n();const s=new MutationObserver(a);return s.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","data-overlay-scroll"]}),window.addEventListener("resize",a),()=>{r&&window.cancelAnimationFrame(r),s.disconnect(),window.removeEventListener("resize",a),document.querySelectorAll(wl).forEach(l=>{var i;l instanceof HTMLElement&&((i=e.get(l))==null||i.destroy())})}},[]),null}function Yt(e){const r=e.trim();return!r||r==="/"||r==="/."?"":(r.startsWith("/")?r:`/${r}`).replace(/\/+$/,"")}function Cl(e){try{const r=new URL(e);return Yt(r.pathname)}catch{return""}}function bf(e){const r=Yt(e);if(!r)return"";const n=r.match(/^\/apps\/[^/]+/i);if(n)return Yt(n[0]);const a=r.split("/").filter(Boolean);return a.length===0?"":a.length>=2&&a[0].toLowerCase()==="apps"?Yt(`/${a[0]}/${a[1]}`):new Set(["admin","apps","apps-list","tickets","my-tickets","projects","projects-calendars","dashboard","teams","clients","services","settings","profile","messages","notifications","my-access","my-registers","my-pings","security-incidents","email-inbox","webhook-config","webphone-config","vobo","auth","api","login","forbidden","unauthorized","change-password","reset-password","chat-widget"]).has(a[0].toLowerCase())?"":Yt(`/${a[0]}`)}const fo="primeSuiteAppUrl",mf={xs:{wh:"w-5 h-5",text:"text-[8px]"},sm:{wh:"w-7 h-7",text:"text-[11px]"},md:{wh:"w-9 h-9",text:"text-sm"},lg:{wh:"w-12 h-12",text:"text-base"},xl:{wh:"w-16 h-16",text:"text-xl"}},El={xs:20,sm:28,md:36,lg:48,xl:64},Ml=["bg-indigo-500","bg-blue-500","bg-emerald-500","bg-violet-500","bg-amber-500","bg-teal-500","bg-rose-500","bg-cyan-500"],pf={xs:"text-xs",sm:"text-sm",md:"text-base",lg:"text-lg"},hf="bonsaif.bot",gf="Bonsaif Bot",vf={xs:"p-0.5",sm:"p-1",md:"p-1.5",lg:"p-2",xl:"p-2.5"};function Tl(e){return typeof e=="string"?e.trim():""}function yf(e){var s;if(e!==void 0)return Yt(e);const r=Yt(typeof process<"u"&&((s=process.env)==null?void 0:s.NEXT_PUBLIC_BASE_PATH)||"");if(r)return r;if(typeof window>"u")return"";try{const i=new URLSearchParams(window.location.search).get(fo)||"";i&&window.sessionStorage.setItem(fo,i);const c=window.sessionStorage.getItem(fo)||"",d=i||c;if(d){const u=Cl(d);if(u&&!/^\/admin(\/|$)/i.test(u))return u}}catch{}const n=window.__NEXT_DATA__,a=(n==null?void 0:n.assetPrefix)||"";if(a){const l=a.startsWith("http")?Cl(a):Yt(a);if(l&&!/^\/admin(\/|$)/i.test(l))return l}return bf(window.location.pathname)}function xf(e){const r=e.split(/\s+/).map(n=>n.trim()).filter(Boolean);return r.length===0?"?":r.length===1?r[0].slice(0,1).toUpperCase():`${r[0].slice(0,1)}${r[1].slice(0,1)}`.toUpperCase()}function wf(e){let r=0;for(const n of e)r=r*31+n.charCodeAt(0)&65535;return Ml[r%Ml.length]}function Nf(e,r){return e===hf||r===gf}function kf(e,r){return`${e.replace(/\/$/,"")}${r}`}function $l({userId:e,username:r,name:n,size:a="md",showName:s=!1,showTooltip:l,tooltipContent:i,fallbackLabel:c="Usuario",basePath:d,wrapperClassName:u="",labelClassName:m="",labelSize:b="xs",avatarVersion:f=0,className:g="",style:v}){const[k,h]=o.useState(!1),C=typeof e=="string"&&e.trim()&&e!=="undefined"&&e!=="null"?e.trim():"";o.useEffect(()=>{h(!1)},[C,f]);const{wh:M,text:y}=mf[a],x=Tl(n)||Tl(r)||c,w=xf(x),N=yf(d),A=Nf(r,n),T=kf(N,"/favicon.svg"),U=o.useMemo(()=>{if(!C)return"";const z=new URLSearchParams;z.set("size",String(El[a])),f&&z.set("v",String(f));const se=z.toString();return`${N}/api/user/avatar/${encodeURIComponent(C)}${se?`?${se}`:""}`},[f,N,C,a]),K=El[a],Z=A?t.jsx("span",{className:`${M} ${vf[a]} rounded-full flex items-center justify-center bg-[#071f1a] ring-1 ring-emerald-400/35 shadow-[0_0_0_1px_rgba(255,255,255,0.06)] flex-shrink-0 ${g}`,style:v,children:t.jsx("img",{src:T,alt:x,width:K,height:K,className:"h-full w-full object-contain"})}):U&&!k?t.jsx("img",{src:U,alt:x,width:K,height:K,className:`${M} rounded-full object-cover flex-shrink-0 ${g}`,style:v,loading:"lazy",referrerPolicy:"no-referrer",onError:()=>h(!0)},`${C}-${f}`):t.jsx("span",{className:`${M} ${wf(x)} ${y} rounded-full flex items-center justify-center font-black text-white uppercase flex-shrink-0 ${g}`,style:v,title:x,children:w});if(s)return t.jsxs("span",{className:`inline-flex min-w-0 items-center gap-2 ${u}`,children:[Z,t.jsx("span",{className:`min-w-0 truncate ${pf[b]} font-medium text-[var(--text-main)] ${m}`,title:x,children:x})]});const L=l??!0,Q=i??x;return L&&Q?t.jsx(nr,{as:"span",content:Q,className:`inline-flex flex-shrink-0 ${u}`,children:Z}):Z}function Sf({href:e,className:r,children:n}){return t.jsx("a",{href:e,className:r,children:n})}function Cf(e){return e.reduce((r,n)=>{const a=n.section??"Principal";return r[a]=[...r[a]??[],n],r},{})}function Al({children:e,navItems:r=[],currentPath:n=typeof window>"u"?"/":window.location.pathname,user:a,appName:s="Bonsaif",appLogo:l,header:i,footer:c,onLogout:d,LinkComponent:u=Sf}){const[m,b]=o.useState(!1),f=Cf(r);return t.jsxs("div",{className:"min-h-screen bg-[var(--bg-main)] text-[var(--text-main)]",children:[t.jsx(Sl,{}),t.jsx("button",{type:"button","aria-label":"Abrir navegación",className:"fixed left-3 top-3 z-50 inline-flex h-9 w-9 items-center justify-center rounded-md border border-white/10 bg-black/70 text-white lg:hidden",onClick:()=>b(!0),children:t.jsx(q.HiBars3,{className:"h-5 w-5"})}),m&&t.jsx("button",{type:"button","aria-label":"Cerrar navegación",className:"fixed inset-0 z-40 bg-black/45 lg:hidden",onClick:()=>b(!1)}),t.jsxs("aside",{className:`fixed inset-y-0 left-0 z-50 flex w-72 flex-col bg-[#071716] text-white shadow-2xl transition-transform duration-200 lg:translate-x-0 ${m?"translate-x-0":"-translate-x-full"}`,children:[t.jsxs("div",{className:"flex h-16 items-center gap-3 border-b border-white/10 px-4",children:[t.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-white/10 text-white",children:l??t.jsx(q.HiHome,{className:"h-5 w-5"})}),t.jsx("div",{className:"min-w-0 flex-1 truncate text-sm font-semibold",children:s}),t.jsx("button",{type:"button","aria-label":"Cerrar navegación",className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-white/70 hover:bg-white/10 lg:hidden",onClick:()=>b(!1),children:t.jsx(q.HiXMark,{className:"h-5 w-5"})})]}),t.jsx("nav",{className:"sidebar-scroll min-h-0 flex-1 overflow-y-auto px-3 py-4","data-overlay-scroll":"true",children:t.jsx("div",{className:"sidebar-scroll-body",children:Object.entries(f).map(([g,v])=>t.jsxs("div",{className:"mb-5",children:[t.jsxs("div",{className:"mb-2 flex items-center gap-2 px-2 text-[11px] font-semibold uppercase tracking-wide text-white/35",children:[t.jsx(q.HiChevronDown,{className:"h-3.5 w-3.5"}),g]}),t.jsx("div",{className:"space-y-1",children:v.map(k=>{const h=n===k.href||n.startsWith(`${k.href}/`);return t.jsxs(u,{href:k.href,className:`flex min-w-0 items-center gap-2 rounded-md px-2 py-2 text-sm transition-colors ${h?"bg-white/10 text-white":"text-white/55 hover:bg-white/[0.06] hover:text-white/85"}`,children:[t.jsx("span",{className:"flex h-5 w-5 flex-shrink-0 items-center justify-center",children:k.icon??t.jsx(q.HiHome,{className:"h-4 w-4"})}),t.jsx("span",{className:"truncate",children:k.label})]},k.href)})})]},g))})}),t.jsxs("div",{className:"border-t border-white/10 p-3",children:[a&&t.jsxs("div",{className:"mb-3 flex min-w-0 items-center gap-3 rounded-lg bg-white/[0.04] p-2",children:[t.jsx($l,{name:a.initials??a.name??a.email??"Usuario",size:"md"}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"truncate text-sm font-medium text-white",children:a.name??"Usuario"}),a.email&&t.jsx("div",{className:"truncate text-xs text-white/45",children:a.email})]})]}),d&&t.jsxs(Ue,{variant:"ghost",className:"w-full justify-start text-white hover:bg-white/10",onClick:d,children:[t.jsx(q.HiArrowRightOnRectangle,{className:"h-4 w-4"})," Salir"]}),c]})]}),t.jsxs("div",{className:"min-h-screen lg:pl-72",children:[i,t.jsx("main",{className:"min-h-screen",children:e})]})]})}const Ll="bonsaif-ui:prime-auth-sso",Ef={dashboard:"Dashboard",tickets:"Tickets",teams:"Equipos",projects:"Proyectos",clients:"Clientes",surveys:"Encuestas",profile:"Perfil",settings:"Configuración",notifications:"Notificaciones",changelog:"Historial",admin:"Inicio",users:"Usuarios",roles:"Roles",menus:"Menús",guards:"Guardias",vacations:"Vacaciones",audit:"Auditoría",positions:"Puestos",ranks:"Rangos","email-inbox":"Buzones","security-incidents":"Incidentes","guard-schedule":"Guardias"},bo={dashboard:t.jsx(q.HiChartBar,{className:"h-5 w-5"}),tickets:t.jsx(q.HiTicket,{className:"h-5 w-5"}),teams:t.jsx(q.HiUsers,{className:"h-5 w-5"}),projects:t.jsx(q.HiRectangleGroup,{className:"h-5 w-5"}),clients:t.jsx(q.HiBuildingOffice2,{className:"h-5 w-5"}),surveys:t.jsx(q.HiClipboardDocumentList,{className:"h-5 w-5"}),profile:t.jsx(q.HiUser,{className:"h-5 w-5"}),settings:t.jsx(q.HiCog6Tooth,{className:"h-5 w-5"}),notifications:t.jsx(q.HiBell,{className:"h-5 w-5"}),changelog:t.jsx(q.HiDocumentText,{className:"h-5 w-5"}),admin:t.jsx(q.HiShieldCheck,{className:"h-5 w-5"}),users:t.jsx(q.HiUsers,{className:"h-5 w-5"}),roles:t.jsx(q.HiShieldCheck,{className:"h-5 w-5"}),menus:t.jsx(q.HiCog6Tooth,{className:"h-5 w-5"}),guards:t.jsx(q.HiCalendarDays,{className:"h-5 w-5"}),vacations:t.jsx(q.HiCalendarDays,{className:"h-5 w-5"}),audit:t.jsx(q.HiListBullet,{className:"h-5 w-5"}),positions:t.jsx(q.HiBriefcase,{className:"h-5 w-5"}),ranks:t.jsx(q.HiListBullet,{className:"h-5 w-5"}),"email-inbox":t.jsx(q.HiInbox,{className:"h-5 w-5"}),"security-incidents":t.jsx(q.HiShieldCheck,{className:"h-5 w-5"})};function Mf(e){return e.split("-").map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" ")}function Tf(e){return/^\d+$/.test(e)||/^[a-f0-9]{8,}$/i.test(e)}function $f(e){const r=e.split("/").filter(Boolean);if(r.length===0||r.length===1&&r[0]==="dashboard")return[];const n=decodeURIComponent(r[r.length-1]),a=r.length>1?decodeURIComponent(r[r.length-2]):void 0,s=Tf(n)&&a?a:n,l=Ef[s]??Mf(s);return[{label:"Inicio",href:"/"},{label:l}]}function mo(e){return(e==null?void 0:e.querySelector(":scope > .os-viewport"))??(e==null?void 0:e.querySelector(":scope > [data-overlayscrollbars-viewport]"))}function Af(e){const r=e.split("/").filter(Boolean),n=r[r.length-1];if(!n)return t.jsx(q.HiHome,{className:"h-5 w-5"});if(bo[n])return bo[n];const a=r.length>1?r[r.length-2]:"";return bo[a]??t.jsx(q.HiHome,{className:"h-5 w-5"})}function Lf(e){return e.includes("primeAuthOrigin")||e.includes("primeAuthProjectKey")}function Dl(){if(typeof window>"u")return!1;if(Lf(window.location.href)){try{window.sessionStorage.setItem(Ll,"true")}catch{}return!0}try{return window.sessionStorage.getItem(Ll)==="true"}catch{return!1}}function Df({title:e,subtitle:r,action:n,meta:a,icon:s,className:l="",contentClassName:i="",breadcrumbs:c,currentPath:d,showBreadcrumbs:u=!0,contained:m=!1}){const b=o.useRef(null),[f,g]=o.useState(!1),[v,k]=o.useState(d??"/"),[h,C]=o.useState(()=>Dl()),[M,y]=o.useState(null),x=d??v,w=c??$f(x),N=s??Af(x),A=u&&!h&&w.length>1,T=!A;o.useEffect(()=>{d||k(window.location.pathname)},[d]),o.useEffect(()=>{C(Dl())},[]),o.useEffect(()=>{if(m){g(!1);return}let K=null,Z=0,L=0;const Q=()=>{const re=b.current,R=document.querySelector("[data-app-scroll='true']");return(re==null?void 0:re.closest(".os-viewport"))??(re==null?void 0:re.closest("[data-overlayscrollbars-viewport]"))??mo(R)??R??window},z=()=>{const re=K&&K!==window?K.scrollTop:window.scrollY;g(R=>R?re>24:re>72)},se=()=>{K==null||K.removeEventListener("scroll",z),K=Q(),K.addEventListener("scroll",z,{passive:!0}),z()};return se(),Z=window.requestAnimationFrame(se),L=window.setTimeout(se,120),()=>{window.cancelAnimationFrame(Z),window.clearTimeout(L),K==null||K.removeEventListener("scroll",z)}},[m]),o.useEffect(()=>{if(m){y(null);return}let K=0;const Z=[],L=()=>{const B=b.current,le=B==null?void 0:B.parentElement,j=document.querySelector("[data-app-scroll='true']"),W=mo(j)??j;if(!B||!le||!W){y(null);return}const ae=le.getBoundingClientRect(),H=window.getComputedStyle(le),D=W.getBoundingClientRect(),$=W instanceof HTMLElement&&W.clientWidth>0?W.clientWidth:D.width,oe=ae.left+parseFloat(H.paddingLeft||"0"),G={marginLeft:Math.round(D.left-oe),width:Math.round($)};y(X=>X&&X.marginLeft===G.marginLeft&&X.width===G.width?X:G)},Q=()=>{window.cancelAnimationFrame(K),K=window.requestAnimationFrame(L)};Q(),window.addEventListener("resize",Q);const z=new ResizeObserver(Q),se=b.current,re=se==null?void 0:se.parentElement,R=document.querySelector("[data-app-scroll='true']"),V=mo(R)??R;return[re,R,V].forEach(B=>{B&&z.observe(B)}),Z.push(window.setTimeout(Q,120)),Z.push(window.setTimeout(Q,280)),()=>{window.cancelAnimationFrame(K),window.removeEventListener("resize",Q),z.disconnect(),Z.forEach(B=>window.clearTimeout(B))}},[m]);const U={...M?{marginLeft:M.marginLeft,width:M.width}:null,"--page-header-control-height":f?"34px":"40px","--page-header-control-padding-x":f?"10px":"14px","--page-header-control-icon-left":f?"10px":"12px",background:m?"var(--bg-card)":f?"color-mix(in srgb, var(--bg-main) 82%, transparent)":"color-mix(in srgb, var(--bg-main) 58%, transparent)",backdropFilter:"saturate(1.25) blur(18px)",WebkitBackdropFilter:"saturate(1.25) blur(18px)",borderBottom:m||f?"1px solid var(--border)":"1px solid transparent",boxShadow:f?"0 10px 28px rgba(12, 54, 53, 0.12)":"none"};return t.jsx("div",{ref:b,"data-page-header":"true","data-compact":f?"true":"false",className:`sticky top-0 z-30 overflow-visible py-0 transition-[background-color,box-shadow,border-color] duration-300 ease-out ${m?"mb-0 flex-shrink-0":"mb-4 sm:mb-0"} ${l}`,style:U,children:t.jsxs("div",{className:`flex flex-wrap items-center justify-between transition-[gap,min-height,padding] duration-300 ease-out ${f?"min-h-8 gap-1.5 px-3 py-0 sm:min-h-9 sm:gap-2":T?"min-h-9 gap-2 px-4 py-0 sm:min-h-10 sm:gap-2.5":"min-h-10 gap-2.5 px-4 pt-0.5 sm:min-h-11 sm:gap-3"} ${i}`,children:[t.jsx("div",{className:`min-w-0 flex flex-1 flex-col justify-center transition-[gap,transform] duration-300 ease-out ${f||T?"gap-1":"gap-1.5 sm:gap-2"}`,children:t.jsxs("div",{className:`flex min-w-0 items-center transition-[gap,transform] duration-300 ease-out ${f||T?"gap-2":"gap-2.5 sm:gap-3"}`,children:[t.jsx("span",{className:`flex-shrink-0 transition-[color,transform,opacity] duration-300 ease-out ${f?"scale-75 opacity-80":"scale-90 opacity-100"}`,style:{color:A?"var(--text-secondary)":"var(--text-muted)"},children:N}),t.jsxs("div",{className:`flex min-w-0 flex-1 flex-wrap items-center transition-[gap] duration-300 ease-out ${f?"gap-x-2 gap-y-1":"gap-x-3 gap-y-2"}`,children:[t.jsxs("div",{className:"min-w-0 flex-shrink transition-[transform] duration-300 ease-out",children:[t.jsx("h1",{className:`truncate font-bold tracking-tight transition-[font-size,line-height,color] duration-300 ease-out ${f?"text-sm sm:text-base":"text-lg sm:text-xl"}`,style:{color:"var(--text-main)"},children:e}),r&&t.jsx("div",{"aria-hidden":f,className:`overflow-hidden text-xs transition-[max-height,opacity,transform,margin] duration-300 ease-out ${f?"mt-0 max-h-0 -translate-y-1 opacity-0":"mt-0.5 max-h-8 translate-y-0 opacity-100"}`,style:{color:"var(--text-muted)"},children:r})]}),a&&t.jsx("div",{className:`page-header-meta flex min-w-0 flex-1 basis-full items-center overflow-visible transition-[gap,opacity,transform] duration-300 ease-out sm:basis-auto ${f?"translate-y-0 gap-1.5 opacity-95":"gap-2 opacity-100"}`,children:a})]})]})}),n&&t.jsx("div",{className:`page-header-actions ml-auto flex max-w-full flex-shrink-0 flex-wrap items-center justify-end self-center overflow-visible transition-[gap,min-height,opacity,transform] duration-300 ease-out ${f?"min-h-9 gap-1 opacity-95":"min-h-9 gap-1.5 opacity-100"}`,children:t.jsx(Po.Provider,{value:{compact:!0,headerAction:!0},children:n})})]})})}function If({children:e,currentPath:r=typeof window>"u"?"/":window.location.pathname,publicRoutes:n=["/","/login","/reset-password"],...a}){return n.includes(r)?t.jsx(t.Fragment,{children:e}):t.jsx(Al,{currentPath:r,...a,children:e})}function Il(){if(typeof window>"u")return"system";const e=localStorage.getItem("theme");return e==="light"||e==="dark"?e:e==="system"?"system":document.documentElement.classList.contains("dark")?"dark":"light"}function Of(e,r,n){try{const a=new URL(e),s=a.searchParams.get("callbackUrl");if(s){const l=new URL(s,a.origin);return l.searchParams.set("theme",r),n&&(l.searchParams.set("primeAuthOrigin",window.location.origin),l.searchParams.set("primeAuthProjectKey",n)),a.searchParams.set("callbackUrl",`${l.pathname}${l.search}${l.hash}`),a.toString()}return a.searchParams.set("theme",r),n&&(a.searchParams.set("primeAuthOrigin",window.location.origin),a.searchParams.set("primeAuthProjectKey",n)),a.toString()}catch{return e}}function Hf({name:e,src:r,projectKey:n}){const[a,s]=o.useState("system"),l=o.useRef(null);o.useEffect(()=>{s(Il());const d=new MutationObserver(()=>s(Il()));return d.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>d.disconnect()},[]);const i=o.useMemo(()=>Of(r,a,n),[n,r,a]),c=o.useMemo(()=>{try{return new URL(i).origin}catch{return""}},[i]);return o.useEffect(()=>{if(!n)return;const d=n;function u(m){var g,v,k;if(m.source!==((g=l.current)==null?void 0:g.contentWindow)||c&&m.origin!==c)return;if(((v=m.data)==null?void 0:v.type)==="prime-microservice:overlay"){window.dispatchEvent(new CustomEvent("prime-auth:microservice-overlay",{detail:{active:!!m.data.active}}));return}if(((k=m.data)==null?void 0:k.type)!=="prime-microservice:navigation")return;const b=m.data.path;if(!b||!b.startsWith("/")||b.startsWith("//"))return;const f=`/apps/${encodeURIComponent(d)}${b}`;`${window.location.pathname}${window.location.search}${window.location.hash}`!==f&&(window.history.replaceState(window.history.state,"",f),window.dispatchEvent(new CustomEvent("prime-auth:microservice-navigation")))}return window.addEventListener("message",u),()=>{window.removeEventListener("message",u),window.dispatchEvent(new CustomEvent("prime-auth:microservice-overlay",{detail:{active:!1}}))}},[c,n]),t.jsx("div",{className:"flex h-full min-h-screen flex-col bg-[var(--bg-main)]",children:t.jsx("iframe",{ref:l,src:i,title:e,className:"min-h-0 flex-1 border-0 bg-[var(--bg-main)]",allow:"clipboard-write",sandbox:"allow-downloads allow-forms allow-modals allow-popups allow-same-origin allow-scripts",referrerPolicy:"strict-origin-when-cross-origin"})})}function Bf(){const[e,r]=o.useState(""),[n,a]=o.useState(!1),[s,l]=o.useState({width:96,height:96});return o.useEffect(()=>{let i=!1;return fetch("/api/microservices/prime-suite/chat-url",{cache:"no-store"}).then(c=>c.ok?c.json():null).then(c=>{!i&&(c!=null&&c.src)&&r(c.src)}).catch(()=>{}),()=>{i=!0}},[]),o.useEffect(()=>{const i=c=>{var u;if(((u=c.data)==null?void 0:u.type)!=="prime-suite-chat:state")return;const d=!!c.data.active;a(d),l({width:Ol(c.data.width,96,720),height:Ol(c.data.height,96,560)})};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)},[]),e?t.jsx("iframe",{title:"Chat Bonsaif",src:e,allow:"clipboard-write",className:"fixed bottom-0 right-0 z-[70] border-0 bg-transparent transition-[width,height] duration-200",style:{width:n?`min(${s.width}px, 100vw)`:96,height:n?`min(${s.height}px, 100vh)`:96,background:"transparent",backgroundColor:"transparent",colorScheme:"normal"}}):null}function Ol(e,r,n){const a=typeof e=="number"&&Number.isFinite(e)?e:r;return Math.max(r,Math.min(n,Math.ceil(a)))}function Ff(e){const r=document.documentElement,n=new MutationObserver(e);n.observe(r,{attributes:!0,attributeFilter:["class"]});const a=window.matchMedia("(prefers-color-scheme: dark)");return a.addEventListener("change",e),()=>{n.disconnect(),a.removeEventListener("change",e)}}function Pf(){const e=localStorage.getItem("theme")||"system",r=window.matchMedia("(prefers-color-scheme: dark)").matches;return document.documentElement.classList.contains("dark")||e==="dark"||e==="system"&&r?"dark":"light"}function _f(){return"light"}function zf({position:e="bottom-center"}){const r=o.useSyncExternalStore(Ff,Pf,_f);return t.jsx(Ho.Toaster,{position:e,theme:r,richColors:!0,closeButton:!0})}function Wf({title:e,subtitle:r,actions:n,loading:a=!1,empty:s=!1,emptyText:l="Sin datos para mostrar",className:i="",children:c}){return t.jsxs("div",{className:`bonsaif-chart-card w-full overflow-visible ${i}`,children:[(e||r||n)&&t.jsxs("div",{className:"bonsaif-chart-card-head",children:[t.jsx("div",{className:"bonsaif-chart-card-accent","aria-hidden":!0}),t.jsxs("div",{className:"bonsaif-chart-card-copy min-w-0",children:[e?t.jsx("div",{className:"bonsaif-chart-card-title",children:e}):null,r?t.jsx("div",{className:"bonsaif-chart-card-subtitle",children:r}):null]}),n?t.jsx("div",{className:"bonsaif-chart-card-actions shrink-0",children:n}):null]}),t.jsx("div",{className:"bonsaif-chart-card-body",children:a?t.jsx("div",{className:"flex h-48 items-center justify-center",children:t.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-2 border-t-transparent",style:{borderColor:"var(--border)",borderTopColor:"var(--primary)"},"aria-label":"Cargando"})}):s?t.jsx("div",{className:"flex h-48 items-center justify-center text-sm",style:{color:"var(--text-muted)"},children:l}):c})]})}const an=["var(--primary)","#38bdf8","#34d399","#a78bfa","#2dd4bf","#fbbf24","#60a5fa","#94a3b8"];function Hl(e,r){return e.color??an[r%an.length]}function Dt(e="primary"){switch(e){case"success":return"#34d399";case"warning":return"#fbbf24";case"danger":return"#f87171";case"neutral":return"var(--text-muted)";default:return"var(--primary)"}}const wt=e=>{if(!Number.isFinite(e))return"—";const r=Math.abs(e);return r>=1e9?`${(e/1e9).toFixed(1).replace(/\.0$/,"")}B`:r>=1e6?`${(e/1e6).toFixed(1).replace(/\.0$/,"")}M`:r>=1e4?`${(e/1e3).toFixed(1).replace(/\.0$/,"")}k`:e.toLocaleString(void 0,{maximumFractionDigits:2})};function Tr(e){if(e==null||e==="")return null;const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?r:null}const po={warning:70,danger:90};function Yn(e,r=po){const n=r.warning??po.warning,a=r.danger??po.danger;return e>=a?"danger":e>=n?"warning":e<=0?"primary":"success"}function on(e,r){return Dt(Yn(e,r))}function $r(e,r=0){return Number.isFinite(e)?`${e.toFixed(r)}%`:"—"}function Ar(e,r=1){if(!Number.isFinite(e))return"—";const n=e<0?"-":"",a=Math.abs(e);if(a<1024)return`${n}${Math.round(a)} B`;const s=["KB","MB","GB","TB","PB"];let l=a/1024,i=0;for(;l>=1024&&i<s.length-1;)l/=1024,i+=1;const c=l>=100?l.toFixed(0):l.toFixed(r);return`${n}${c.replace(/\.0$/,"")} ${s[i]}`}function Bl(e,r="bytes",n=1){if(!Number.isFinite(e))return"—";const a=e<0?"-":"",s=Math.abs(e),l=r==="bits"?["b/s","Kb/s","Mb/s","Gb/s","Tb/s"]:["B/s","KB/s","MB/s","GB/s","TB/s"];if(s<1024)return`${a}${Math.round(s)} ${l[0]}`;let i=s/1024,c=1;for(;i>=1024&&c<l.length-1;)i/=1024,c+=1;const d=i>=100?i.toFixed(0):i.toFixed(n);return`${a}${d.replace(/\.0$/,"")} ${l[c]}`}function Lr(e,r){var n;for(let a=e.length-1;a>=0;a-=1){const s=Tr((n=e[a])==null?void 0:n[r]);if(s!==null)return s}return null}function Nt({height:e}){return t.jsx("div",{className:"flex items-center justify-center",style:{height:e},"aria-busy":!0,children:t.jsx("div",{className:"h-7 w-7 animate-spin rounded-full border-2",style:{borderColor:"var(--border)",borderTopColor:"var(--primary)"}})})}function kt({height:e,text:r}){return t.jsx("div",{className:"flex items-center justify-center text-sm",style:{height:e,color:"var(--text-muted)"},children:r})}const Xt=680,sr="ease-out",jf={top:18,right:8,bottom:12,left:0};function sn(e){return{...jf,...e}}function ln(e){return e.map((r,n)=>({...r,color:Hl(r,n),label:r.label??r.key}))}function Xn(e,r){return!e.length||!r.length||e.every(n=>r.every(a=>Tr(n[a.key])===null))}function St(){return{fill:"var(--text-muted)",fontSize:10,fontWeight:500,letterSpacing:"0.02em"}}function cn(){return"color-mix(in srgb, var(--border) 55%, transparent)"}function Fl(){return"color-mix(in srgb, var(--primary) 45%, var(--border))"}function Kn(){return{paddingBottom:12,paddingLeft:4,fontSize:11,fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"var(--text-muted)"}}function qf(e,r=wt){if(e==null||e==="")return"—";const n=typeof e=="number"?e:Number(e);return Number.isFinite(n)?r(n):String(e)}function Pl(e){return`bonsaif-grad-${e.replace(/[^a-zA-Z0-9_-]/g,"")}`}function Uf({active:e,label:r,payload:n,valueFormat:a=wt}){var c,d,u,m,b,f;if(!e||!(n!=null&&n.length))return null;const s=n.filter(g=>g.dataKey!=="base"&&g.name!=="base"&&g.value!==null&&g.value!==void 0);if(!s.length)return null;const l=((d=(c=s[0])==null?void 0:c.payload)==null?void 0:d.fullName)??((m=(u=s[0])==null?void 0:u.payload)==null?void 0:m.tooltipLabel)??((f=(b=s[0])==null?void 0:b.payload)==null?void 0:f.display),i=typeof l=="string"&&l.length>0?l:r;return t.jsxs("div",{className:"bonsaif-chart-tooltip-panel",children:[i!=null&&i!==""?t.jsx("div",{className:"bonsaif-chart-tooltip-label",children:String(i)}):null,t.jsx("div",{className:"bonsaif-chart-tooltip-items",children:s.map((g,v)=>{const k=g.payload,h=k&&typeof k.display=="number"?k.display:g.value;return t.jsxs("div",{className:"bonsaif-chart-tooltip-row",children:[t.jsxs("span",{className:"bonsaif-chart-tooltip-name",children:[t.jsx("span",{className:"bonsaif-chart-tooltip-swatch",style:{background:g.color??"var(--primary)"}}),g.name??g.dataKey]}),t.jsx("span",{className:"bonsaif-chart-tooltip-value",children:qf(h,a)})]},String(g.dataKey??g.name??v))})})]})}function Dr({valueFormat:e,content:r,cursor:n,offset:a=12,wrapperStyle:s,allowEscapeViewBox:l,reverseDirection:i,...c}){return t.jsx(Ce.Tooltip,{...c,cursor:n,offset:a,allowEscapeViewBox:l??{x:!1,y:!1},reverseDirection:i??{x:!1,y:!1},wrapperStyle:{outline:"none",zIndex:60,pointerEvents:"none",overflow:"visible",...s},content:r??t.jsx(Uf,{valueFormat:e})})}function _l(e,r,n){return n==null?-1:e.findIndex(a=>String(a[r])===String(n))}function zl(e,r,n){if(n<=1)return null;const a=Math.max(0,Math.min(e,r)),s=Math.min(n-1,Math.max(e,r));return s-a<1||a===0&&s>=n-1?null:{startIndex:a,endIndex:s}}function Gn(e,r,n={}){const{zoomable:a=!1,zoomMode:s="both",brushHeight:l=28,onZoomChange:i}=n,[c,d]=o.useState(null),[u,m]=o.useState(null),b=!!a&&e.length>1,f=b&&(s==="brush"||s==="both"),g=b&&(s==="drag"||s==="both"),v=o.useCallback(Z=>{d(Z),i==null||i(Z)},[i]),k=o.useCallback(()=>{m(null),v(null)},[v]),h=!!c,C=o.useMemo(()=>!c||f?e:e.slice(c.startIndex,c.endIndex+1),[e,f,c]),M=o.useCallback((Z,L)=>{const Q=_l(e,r,Z),z=_l(e,r,L);Q<0||z<0||v(zl(Q,z,e.length))},[v,e,r]),y=o.useCallback(Z=>{g&&((Z==null?void 0:Z.activeLabel)===void 0||(Z==null?void 0:Z.activeLabel)===null||m({leftLabel:Z.activeLabel,rightLabel:Z.activeLabel}))},[g]),x=o.useCallback(Z=>{!g||!u||(Z==null?void 0:Z.activeLabel)===void 0||(Z==null?void 0:Z.activeLabel)===null||m(L=>L&&{...L,rightLabel:Z.activeLabel})},[u,g]),w=o.useCallback(()=>{if(g){if(!u||u.rightLabel===null||u.rightLabel===void 0){m(null);return}M(u.leftLabel,u.rightLabel),m(null)}},[M,u,g]),N=o.useCallback(Z=>{if(f){if(!Z){v(null);return}v(zl(Z.startIndex??0,Z.endIndex??e.length-1,e.length))}},[v,e.length,f]),A=g?{onMouseDown:y,onMouseMove:x,onMouseUp:w,onMouseLeave:()=>{u&&w()}}:{},T=c??{startIndex:0,endIndex:Math.max(0,e.length-1)},U=t.jsxs(t.Fragment,{children:[g&&u&&u.rightLabel!==null&&u.rightLabel!==void 0?t.jsx(Ce.ReferenceArea,{x1:u.leftLabel,x2:u.rightLabel,strokeOpacity:.18,fill:"var(--primary)",fillOpacity:.12,stroke:"var(--primary)"}):null,f?t.jsx(Ce.Brush,{dataKey:r,height:l,stroke:"var(--primary)",fill:"color-mix(in srgb, var(--primary) 10%, var(--bg-card))",travellerWidth:8,startIndex:T.startIndex,endIndex:T.endIndex,onChange:N,tickFormatter:Z=>String(Z)}):null]}),K=f?{bottom:Math.max(l+10,36)}:void 0;return{enabled:b,showBrush:f,showDrag:g,viewData:C,isZoomed:h,resetZoom:k,chartHandlers:A,zoomNodes:U,marginExtra:K}}function Zn({visible:e,onReset:r}){return e?t.jsx("button",{type:"button",className:"bonsaif-chart-zoom-reset",onClick:r,"aria-label":"Restablecer zoom",children:"Restablecer zoom"}):null}function Vf({data:e,xKey:r,series:n,height:a=280,className:s="",loading:l=!1,emptyText:i="Sin datos para mostrar",showGrid:c=!0,showLegend:d=!0,showTooltip:u=!0,margin:m,valueFormat:b=wt,yDomain:f,ariaLabel:g="Gráfico de líneas",curve:v=!0,strokeWidth:k=2.25,zoomable:h=!1,zoomMode:C="both",brushHeight:M,onZoomChange:y}){const x=Xn(e,n),w=ln(n),N=Gn(e,r,{zoomable:h,zoomMode:C,brushHeight:M,onZoomChange:y}),A=sn({...m,...N.marginExtra});return l?t.jsx(Nt,{height:a}):x?t.jsx(kt,{height:a,text:i}):t.jsxs("div",{className:`bonsaif-chart bonsaif-line-chart w-full ${s}`,role:"img","aria-label":g,style:{height:a},children:[t.jsx(Zn,{visible:N.isZoomed,onReset:N.resetZoom}),t.jsx(Ce.ResponsiveContainer,{width:"100%",height:"100%",children:t.jsxs(Ce.LineChart,{data:N.viewData,margin:A,...N.chartHandlers,children:[c?t.jsx(Ce.CartesianGrid,{strokeDasharray:"2 8",stroke:cn(),vertical:!1}):null,t.jsx(Ce.XAxis,{dataKey:r,tick:St(),tickLine:!1,axisLine:!1,padding:{left:0,right:0},interval:"preserveStartEnd",minTickGap:52,dy:6}),t.jsx(Ce.YAxis,{tick:St(),tickLine:!1,axisLine:!1,width:44,domain:f??["auto","auto"],tickFormatter:T=>b(Number(T)),dx:-2}),u?t.jsx(Dr,{valueFormat:b,cursor:{stroke:Fl(),strokeWidth:1.25,strokeDasharray:"4 4"}}):null,d?t.jsx(Ce.Legend,{verticalAlign:"top",align:"right",iconType:"circle",iconSize:7,wrapperStyle:Kn()}):null,w.map((T,U)=>t.jsx(Ce.Line,{type:v?"monotone":"linear",dataKey:T.key,name:T.label,stroke:T.color,strokeWidth:U===0?k+.35:k,strokeOpacity:U===0?1:.88,isAnimationActive:!0,animationDuration:Xt,animationEasing:sr,dot:!1,activeDot:{r:5,strokeWidth:2,stroke:"var(--bg-card)",fill:T.color}},T.key)),N.zoomNodes]})})]})}function Qn({data:e,xKey:r,series:n,height:a=280,className:s="",loading:l=!1,emptyText:i="Sin datos para mostrar",showGrid:c=!0,showLegend:d=!0,showTooltip:u=!0,margin:m,valueFormat:b=wt,yDomain:f,ariaLabel:g="Gráfico de área",stacked:v=!1,opacity:k=.22,zoomable:h=!1,zoomMode:C="both",brushHeight:M,onZoomChange:y}){const x=Xn(e,n),w=ln(n),N=Gn(e,r,{zoomable:h,zoomMode:C,brushHeight:M,onZoomChange:y}),A=sn({...m,...N.marginExtra});return l?t.jsx(Nt,{height:a}):x?t.jsx(kt,{height:a,text:i}):t.jsxs("div",{className:`bonsaif-chart bonsaif-area-chart w-full ${s}`,role:"img","aria-label":g,style:{height:a},children:[t.jsx(Zn,{visible:N.isZoomed,onReset:N.resetZoom}),t.jsx(Ce.ResponsiveContainer,{width:"100%",height:"100%",children:t.jsxs(Ce.AreaChart,{data:N.viewData,margin:A,...N.chartHandlers,children:[t.jsx("defs",{children:w.map(T=>t.jsxs("linearGradient",{id:Pl(T.key),x1:"0",y1:"0",x2:"0",y2:"1",children:[t.jsx("stop",{offset:"0%",stopColor:T.color,stopOpacity:Math.min(.55,k+.28)}),t.jsx("stop",{offset:"48%",stopColor:T.color,stopOpacity:k*.5}),t.jsx("stop",{offset:"100%",stopColor:T.color,stopOpacity:0})]},T.key))}),c?t.jsx(Ce.CartesianGrid,{strokeDasharray:"2 8",stroke:cn(),vertical:!1}):null,t.jsx(Ce.XAxis,{dataKey:r,tick:St(),tickLine:!1,axisLine:!1,padding:{left:0,right:0},interval:"preserveStartEnd",minTickGap:52,dy:6}),t.jsx(Ce.YAxis,{tick:St(),tickLine:!1,axisLine:!1,width:44,domain:f??["auto","auto"],tickFormatter:T=>b(Number(T)),dx:-2}),u?t.jsx(Dr,{valueFormat:b,cursor:{stroke:Fl(),strokeWidth:1.25,strokeDasharray:"4 4"}}):null,d?t.jsx(Ce.Legend,{verticalAlign:"top",align:"right",iconType:"circle",iconSize:7,wrapperStyle:Kn()}):null,w.map(T=>t.jsx(Ce.Area,{type:"monotone",dataKey:T.key,name:T.label,stroke:T.color,fill:`url(#${Pl(T.key)})`,strokeWidth:2.25,stackId:v?"stack":void 0,isAnimationActive:!0,animationDuration:Xt,animationEasing:sr,dot:!1,activeDot:{r:5,strokeWidth:2,stroke:"var(--bg-card)",fill:T.color}},T.key)),N.zoomNodes]})})]})}function Yf({data:e,xKey:r,series:n,height:a=280,className:s="",loading:l=!1,emptyText:i="Sin datos para mostrar",showGrid:c=!0,showLegend:d=!0,showTooltip:u=!0,margin:m,valueFormat:b=wt,yDomain:f,ariaLabel:g="Gráfico de barras",layout:v="vertical",mode:k="grouped",barRadius:h=6,categoryAxisWidth:C=64,zoomable:M=!1,zoomMode:y="both",brushHeight:x,onZoomChange:w}){const N=Xn(e,n),A=ln(n),T=v==="horizontal",U=Gn(e,r,{zoomable:M&&!T,zoomMode:y,brushHeight:x,onZoomChange:w}),K=sn({...m,...U.marginExtra});return l?t.jsx(Nt,{height:a}):N?t.jsx(kt,{height:a,text:i}):t.jsxs("div",{className:`bonsaif-chart bonsaif-bar-chart w-full ${s}`,role:"img","aria-label":g,style:{height:a},children:[t.jsx(Zn,{visible:U.isZoomed,onReset:U.resetZoom}),t.jsx(Ce.ResponsiveContainer,{width:"100%",height:"100%",children:t.jsxs(Ce.BarChart,{data:U.viewData,margin:K,layout:T?"vertical":"horizontal",barCategoryGap:"34%",barGap:3,...U.chartHandlers,children:[c?t.jsx(Ce.CartesianGrid,{strokeDasharray:"2 8",stroke:cn(),horizontal:!T,vertical:T}):null,T?t.jsxs(t.Fragment,{children:[t.jsx(Ce.XAxis,{type:"number",tick:St(),tickLine:!1,axisLine:!1,tickFormatter:Z=>b(Number(Z)),domain:f??["auto","auto"]}),t.jsx(Ce.YAxis,{type:"category",dataKey:r,tick:St(),tickLine:!1,axisLine:!1,width:C})]}):t.jsxs(t.Fragment,{children:[t.jsx(Ce.XAxis,{dataKey:r,tick:St(),tickLine:!1,axisLine:!1,interval:"preserveStartEnd",minTickGap:36,dy:6}),t.jsx(Ce.YAxis,{tick:St(),tickLine:!1,axisLine:!1,width:44,domain:f??["auto","auto"],tickFormatter:Z=>b(Number(Z)),dx:-2})]}),u?t.jsx(Dr,{valueFormat:b,cursor:{fill:"color-mix(in srgb, var(--primary) 8%, transparent)"}}):null,d?t.jsx(Ce.Legend,{verticalAlign:"top",align:"right",iconType:"circle",iconSize:7,wrapperStyle:Kn()}):null,A.map((Z,L)=>t.jsx(Ce.Bar,{dataKey:Z.key,name:Z.label,fill:Z.color,fillOpacity:L===0?1:.82,radius:T?[0,h,h,0]:[h,h,2,2],maxBarSize:20,stackId:k==="stacked"?"stack":void 0,isAnimationActive:!0,animationDuration:Xt,animationEasing:sr},Z.key)),U.zoomNodes]})})]})}function Xf(e){return t.jsx(jl,{...e,variant:"pie"})}function Kf(e){return t.jsx(jl,{...e,variant:"donut",innerRadius:e.innerRadius??.62,cornerRadius:e.cornerRadius??10,padAngle:e.padAngle??2})}function Wl(e,r){return e==null||!Number.isFinite(e)?r:e>0&&e<=1?e*100:e}function jl({data:e,nameKey:r,valueKey:n,height:a=280,className:s="",loading:l=!1,emptyText:i="Sin datos para mostrar",showLegend:c=!0,showTooltip:d=!0,valueFormat:u=wt,ariaLabel:m,innerRadius:b,outerRadius:f,colors:g=[...an],padAngle:v,cornerRadius:k,variant:h}){const C=e.map((L,Q)=>({name:String(L[r]??""),value:Tr(L[n])??0,fill:g[Q%g.length],row:L})).filter(L=>L.value>0),M=!C.length,y=h==="donut",x=C.length,w=Wl(b,y?62:12),N=Wl(f,78),A=Math.min(v??(y?2:3),Math.max(.5,10/Math.max(1,x))),T=Math.min(k??(y?10:8),Math.max(2,36/Math.max(1,x)));if(l)return t.jsx(Nt,{height:a});if(M)return t.jsx(kt,{height:a,text:i});const U=C.reduce((L,Q)=>L+Q.value,0),K=c?Math.min(96,28+Math.ceil(x/3)*22):0,Z=Math.max(140,a-K);return t.jsx("div",{className:`bonsaif-chart bonsaif-${h}-chart w-full ${s}`,role:"img","aria-label":m??(h==="donut"?"Donut chart":"Pie chart"),style:{height:a},children:t.jsxs("div",{className:"bonsaif-pie-layout",children:[t.jsx("div",{className:"bonsaif-pie-plot",style:{height:Z},children:t.jsx(Ce.ResponsiveContainer,{width:"100%",height:"100%",children:t.jsxs(Ce.PieChart,{margin:{top:4,right:4,bottom:4,left:4},children:[d?t.jsx(Dr,{valueFormat:u,isAnimationActive:!1}):null,t.jsx(Ce.Pie,{data:C,dataKey:"value",nameKey:"name",cx:"50%",cy:"50%",innerRadius:`${w}%`,outerRadius:`${N}%`,startAngle:90,endAngle:-270,paddingAngle:A,cornerRadius:T,minAngle:x>6?3:2,stroke:"var(--bg-card)",strokeWidth:2,isAnimationActive:!0,animationDuration:Xt,animationEasing:sr,label:!1,activeShape:Gf,children:C.map(L=>t.jsx(Ce.Cell,{fill:L.fill},L.name))}),y?t.jsx("text",{x:"50%",y:"50%",textAnchor:"middle",dominantBaseline:"middle",fill:"var(--text-main)",fontSize:18,fontWeight:700,letterSpacing:"-0.02em",children:u(U)}):null]})})}),c?t.jsx("ul",{className:"bonsaif-pie-legend","aria-label":"Leyenda",children:C.map(L=>t.jsxs("li",{className:"bonsaif-pie-legend-item",children:[t.jsx("span",{className:"bonsaif-pie-legend-swatch",style:{background:L.fill},"aria-hidden":!0}),t.jsx("span",{className:"bonsaif-pie-legend-label",title:L.name,children:L.name}),t.jsx("span",{className:"bonsaif-pie-legend-value",children:u(L.value)})]},L.name))}):null]})})}function Gf(e){const{outerRadius:r=0,...n}=e;return t.jsx(Ce.Sector,{...n,outerRadius:Number(r)+4,stroke:"var(--bg-card)",strokeWidth:2})}function Zf({data:e,dataKey:r,width:n="100%",height:a=36,tone:s="primary",color:l,fill:i=!0,className:c="",ariaLabel:d="Sparkline"}){const u=l??Dt(s),m=e.map(N=>Tr(N[r])).filter(N=>N!==null);if(m.length<2)return t.jsx("div",{className:c,style:{width:n,height:a,color:"var(--text-muted)"},"aria-label":d});const b=120,f=36,g=3,v=1,k=Math.min(...m),C=Math.max(...m)-k||1,M=m.map((N,A)=>{const T=v+A/(m.length-1)*(b-v*2),U=f-g-(N-k)/C*(f-g*2);return{x:T,y:U}}),y=M.map((N,A)=>`${A===0?"M":"L"}${N.x.toFixed(2)} ${N.y.toFixed(2)}`).join(" "),x=`${y} L${M[M.length-1].x.toFixed(2)} ${f} L${M[0].x.toFixed(2)} ${f} Z`,w=`bonsaif-spark-${r.replace(/[^a-zA-Z0-9_-]/g,"")}-${s}`;return t.jsx("div",{className:`bonsaif-sparkline ${c}`,style:{width:n,height:a},role:"img","aria-label":d,children:t.jsxs("svg",{width:"100%",height:"100%",viewBox:`0 0 ${b} ${f}`,preserveAspectRatio:"none",focusable:"false",children:[i?t.jsx("defs",{children:t.jsxs("linearGradient",{id:w,x1:"0",y1:"0",x2:"0",y2:"1",children:[t.jsx("stop",{offset:"0%",stopColor:u,stopOpacity:.38}),t.jsx("stop",{offset:"100%",stopColor:u,stopOpacity:0})]})}):null,i?t.jsx("path",{d:x,fill:`url(#${w})`}):null,t.jsx("path",{d:y,fill:"none",stroke:u,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",vectorEffect:"non-scaling-stroke"})]})})}function Qf({data:e,xKey:r,series:n,barSeries:a,lineSeries:s,height:l=280,className:i="",loading:c=!1,emptyText:d="Sin datos para mostrar",showGrid:u=!0,showLegend:m=!0,showTooltip:b=!0,margin:f,valueFormat:g=wt,yDomain:v,ariaLabel:k="Gráfico combinado",barRadius:h=6,zoomable:C=!1,zoomMode:M="both",brushHeight:y,onZoomChange:x}){const w=a??n.slice(0,Math.max(1,n.length-1)),N=s??(n.length>1?n.slice(-1):n.length?[n[0]]:[]),A=[...w,...N.filter(z=>!w.some(se=>se.key===z.key))],T=Xn(e,A),U=ln(w),K=ln(A),Z=N.map(z=>{var re;const se=K.find(R=>R.key===z.key);return{...z,label:z.label??z.key,color:z.color??(se==null?void 0:se.color)??((re=K[0])==null?void 0:re.color)}}),L=Gn(e,r,{zoomable:C,zoomMode:M,brushHeight:y,onZoomChange:x}),Q=sn({...f,...L.marginExtra});return c?t.jsx(Nt,{height:l}):T?t.jsx(kt,{height:l,text:d}):t.jsxs("div",{className:`bonsaif-chart bonsaif-combo-chart w-full ${i}`,role:"img","aria-label":k,style:{height:l},children:[t.jsx(Zn,{visible:L.isZoomed,onReset:L.resetZoom}),t.jsx(Ce.ResponsiveContainer,{width:"100%",height:"100%",children:t.jsxs(Ce.ComposedChart,{data:L.viewData,margin:Q,barCategoryGap:"34%",...L.chartHandlers,children:[u?t.jsx(Ce.CartesianGrid,{strokeDasharray:"2 8",stroke:cn(),vertical:!1}):null,t.jsx(Ce.XAxis,{dataKey:r,tick:St(),tickLine:!1,axisLine:!1,interval:"preserveStartEnd",minTickGap:36,dy:6}),t.jsx(Ce.YAxis,{tick:St(),tickLine:!1,axisLine:!1,width:44,domain:v??["auto","auto"],tickFormatter:z=>g(Number(z)),dx:-2}),b?t.jsx(Dr,{valueFormat:g,cursor:{fill:"color-mix(in srgb, var(--primary) 8%, transparent)"}}):null,m?t.jsx(Ce.Legend,{verticalAlign:"top",align:"right",iconType:"circle",iconSize:7,wrapperStyle:Kn()}):null,U.map(z=>t.jsx(Ce.Bar,{dataKey:z.key,name:z.label,fill:z.color,fillOpacity:.88,radius:[h,h,2,2],maxBarSize:18,isAnimationActive:!0,animationDuration:Xt,animationEasing:sr},z.key)),Z.map(z=>t.jsx(Ce.Line,{type:"monotone",dataKey:z.key,name:z.label,stroke:z.color,strokeWidth:2.5,isAnimationActive:!0,animationDuration:Xt,animationEasing:sr,dot:!1,activeDot:{r:5,strokeWidth:2,stroke:"var(--bg-card)",fill:z.color}},z.key)),L.zoomNodes]})})]})}function Jf({data:e,xKey:r,valueKey:n,typeKey:a,height:s=280,className:l="",loading:i=!1,emptyText:c="Sin datos para mostrar",showGrid:d=!0,showTooltip:u=!0,margin:m,valueFormat:b=wt,ariaLabel:f="Gráfico waterfall",increaseColor:g="#34d399",decreaseColor:v="#f87171",totalColor:k="var(--primary)"}){const h=o.useMemo(()=>Rf(e,{xKey:r,valueKey:n,typeKey:a,increaseColor:g,decreaseColor:v,totalColor:k}),[e,r,n,a,g,v,k]),C=!h.length,M=sn(m);return i?t.jsx(Nt,{height:s}):C?t.jsx(kt,{height:s,text:c}):t.jsx("div",{className:`bonsaif-chart bonsaif-waterfall-chart w-full ${l}`,role:"img","aria-label":f,style:{height:s},children:t.jsx(Ce.ResponsiveContainer,{width:"100%",height:"100%",children:t.jsxs(Ce.BarChart,{data:h,margin:M,barCategoryGap:"42%",children:[d?t.jsx(Ce.CartesianGrid,{strokeDasharray:"2 8",stroke:cn(),vertical:!1}):null,t.jsx(Ce.XAxis,{dataKey:"label",tick:St(),tickLine:!1,axisLine:!1,interval:0,dy:6}),t.jsx(Ce.YAxis,{tick:St(),tickLine:!1,axisLine:!1,width:44,tickFormatter:y=>b(Number(y)),dx:-2}),u?t.jsx(Dr,{valueFormat:b,cursor:{fill:"color-mix(in srgb, var(--primary) 8%, transparent)"}}):null,t.jsx(Ce.Bar,{dataKey:"base",stackId:"wf",fill:"transparent",isAnimationActive:!1,legendType:"none",maxBarSize:22}),t.jsx(Ce.Bar,{dataKey:"delta",name:"Valor",stackId:"wf",radius:[6,6,2,2],maxBarSize:22,isAnimationActive:!0,animationDuration:Xt,animationEasing:sr,children:h.map(y=>t.jsx(Ce.Cell,{fill:y.color},y.label))})]})})})}function Rf(e,r){let n=0;return e.map((a,s)=>{const l=Tr(a[r.valueKey])??0,i=r.typeKey?String(a[r.typeKey]??""):"",c=i==="total"||s===e.length-1&&i!=="increase"&&i!=="decrease";let d="increase",u=0,m=0,b=l;return c&&i==="total"?(d="total",u=0,m=Math.abs(l),b=l,n=l):c&&s===e.length-1&&!i?(d="total",u=0,m=Math.abs(n),b=n):(d=i==="decrease"||l<0?"decrease":"increase",d==="decrease"?(u=n+l,m=Math.abs(l),n=n+l):(u=n,m=Math.abs(l),n=n+l),b=l),{label:String(a[r.xKey]??""),base:u,delta:m,display:b,kind:d,color:d==="total"?r.totalColor:d==="decrease"?r.decreaseColor:r.increaseColor}})}const ql="bonsaif-funnel-chart-keyframes",eb=`
44
+ `}),T.map(O=>{const re=tf(O.colorIndex);return L===O.id?t.jsx("input",{ref:te,value:W,disabled:s,onChange:z=>X(z.target.value),onKeyDown:z=>E(z,O.id),onBlur:()=>ae(O.id,W),className:"min-w-[4rem] rounded border border-[var(--primary)] bg-transparent px-1 py-0.5 text-sm text-[var(--text-main)] outline-none",style:{width:`${Math.max(W.length+2,6)}ch`}},O.id):t.jsxs("span",{className:"inline-flex max-w-[240px] items-center gap-1 rounded-md px-2 py-0.5 text-xs font-medium",style:{backgroundColor:re.bg,color:re.text,border:`1px solid ${re.border}`},children:[t.jsx("span",{className:"truncate",children:O.value}),t.jsx("button",{type:"button","aria-label":`Editar "${O.value}"`,disabled:s,tabIndex:-1,onClick:z=>{z.stopPropagation(),B(O)},className:"flex h-4 w-4 flex-shrink-0 items-center justify-center rounded opacity-60 transition-opacity hover:opacity-100 focus:outline-none disabled:pointer-events-none",children:t.jsx(q.HiPencil,{className:"h-3 w-3"})}),t.jsx("button",{type:"button","aria-label":`Eliminar "${O.value}"`,disabled:s,tabIndex:-1,onClick:z=>{z.stopPropagation(),_(O.id)},className:"flex h-4 w-4 flex-shrink-0 items-center justify-center rounded opacity-60 transition-opacity hover:opacity-100 focus:outline-none disabled:pointer-events-none",children:t.jsx(q.HiXMark,{className:"h-3.5 w-3.5"})})]},O.id)}),!H&&t.jsx("input",{ref:se,value:x,disabled:s,placeholder:T.length===0?a:"",onChange:O=>y(O.target.value),onKeyDown:I,onPaste:K,className:"min-w-[8rem] flex-1 bg-transparent text-sm text-[var(--text-main)] outline-none placeholder:text-[var(--text-muted)] disabled:cursor-not-allowed"})]}),t.jsx(wr,{error:g,helperText:b,helperDisplay:f})]})}const sf=/^(\d{1,2}):(\d{2})(?::(\d{2}))?$/;function Je(e){return String(e).padStart(2,"0")}function mo(e,r=Mr()){const n=e.trim();if(!n)return r;const a=n.match(sf);if(!a)return r;const s=Number(a[1]),l=Number(a[2]),i=a[3]?Number(a[3]):0;return!Number.isFinite(s)||!Number.isFinite(l)||!Number.isFinite(i)||s<0||s>23||l<0||l>59||i<0||i>59?r:{hour24:s,minute:l,second:i}}function an(e,r=!0){const n=`${Je(e.hour24)}:${Je(e.minute)}`;return r?`${n}:${Je(e.second)}`:n}function Kn(e){const r=e.hour24>=12?"PM":"AM";return{hour12:e.hour24%12===0?12:e.hour24%12,minute:e.minute,second:e.second,meridiem:r}}function on(e){let n=Math.min(12,Math.max(1,e.hour12))%12;return e.meridiem==="PM"&&(n+=12),{hour24:n,minute:Math.min(59,Math.max(0,e.minute)),second:Math.min(59,Math.max(0,e.second))}}function lf(e,r){const n=(r==null?void 0:r.use12Hour)??!1,a=(r==null?void 0:r.showSeconds)??!0,s=mo(e);if(n){const l=Kn(s),i=`${l.hour12}:${Je(l.minute)}`;return`${a?`${i}:${Je(l.second)}`:i} ${l.meridiem}`}return an(s,a)}function Mr(){const e=new Date;return{hour24:e.getHours(),minute:e.getMinutes(),second:e.getSeconds()}}function cf(e=!0){return an(Mr(),e)}function po(e,r){const n=[];for(let a=e;a<=r;a+=1)n.push(a);return n}const ht=36,ho=5,wl=Math.floor(ho/2),df=52,uf=48,zt=18;function Nl(e){return e*ht}function kl(e){return Math.round(e/ht)}function ff(e){return e.use12Hour??e.hour12??!1}function Gn({values:e,selected:r,onSelect:n,syncEpochRef:a,forceSyncAt:s=0,width:l=df,label:i,maxNumeric:c=59,isMeridiem:d=!1,isFocused:u=!1,onFocus:m,onAdvance:b,onBack:f,setColumnRef:g}){const v=o.useRef(null),k=o.useRef(null),h=o.useRef(null),A=o.useRef(""),$=o.useRef(0),N=o.useRef(!1),[T,x]=o.useState(r),[y,L]=o.useState(""),w=o.useCallback(B=>{A.current=B,L(B)},[]),W=o.useMemo(()=>[...Array(wl).fill(""),...e,...Array(wl).fill("")],[e]),X=o.useCallback(()=>{const B=v.current;if(!B)return r;const I=kl(B.scrollTop),E=Math.min(Math.max(I,0),e.length-1);return e[E]??r},[r,e]),Z=o.useCallback((B,I=!0)=>{const E=Math.min(Math.max(B,0),e.length-1),oe=e[E],K=v.current;!K||!oe||(k.current&&(window.clearTimeout(k.current),k.current=null),N.current=!0,$.current=E,K.scrollTop=Nl(E),x(oe),I&&oe!==r&&n(oe))},[n,r,e]);o.useLayoutEffect(()=>{k.current&&(window.clearTimeout(k.current),k.current=null),h.current&&(window.clearTimeout(h.current),h.current=null),w(""),x(r);const B=e.indexOf(r);if(B>=0&&($.current=B),B<0||!v.current)return;const I=Nl(B);v.current.scrollTop!==I&&(v.current.scrollTop=I)},[s,r,w,e]);const D=o.useCallback(()=>{h.current&&(window.clearTimeout(h.current),h.current=null)},[]),Q=o.useCallback((B,I=!1)=>{D(),w("");const E=Number(B);if(!Number.isFinite(E))return;const oe=Math.min(c,Math.max(0,E));let K=Je(oe),Y=e.indexOf(K);if(Y<0){const S=Math.min(e.length-1,Math.max(0,oe-(c===12?1:0)));K=e[S]??K,Y=e.indexOf(K)}Y>=0&&Z(Y),I&&(b==null||b())},[D,c,b,Z,w,e]),j=o.useCallback(B=>{const I=Math.floor(c/10),E=A.current;if(E===""){if(B>I){Q(String(B),!0);return}const K=String(B);w(K),h.current=window.setTimeout(()=>{Q(A.current,!0)},1200);return}D();const oe=+`${E}${B}`;oe<=c?Q(String(oe),!0):Q(String(B),!0)},[D,Q,c,w]),se=o.useCallback(B=>{D(),w(""),Z($.current+B)},[D,Z,w]),te=B=>{if(d){B.key==="a"||B.key==="A"?(B.preventDefault(),n("AM"),b==null||b()):B.key==="p"||B.key==="P"?(B.preventDefault(),n("PM"),b==null||b()):B.key==="ArrowUp"||B.key==="ArrowDown"?(B.preventDefault(),n(r==="AM"?"PM":"AM")):B.key==="Tab"&&(B.preventDefault(),B.shiftKey?f==null||f():b==null||b());return}if(/^\d$/.test(B.key)){B.preventDefault(),j(Number(B.key));return}B.key==="ArrowUp"?(B.preventDefault(),se(-1)):B.key==="ArrowDown"?(B.preventDefault(),se(1)):B.key==="Tab"&&(B.preventDefault(),D(),A.current!==""&&Q(A.current,!1),B.shiftKey?f==null||f():b==null||b())},ee=o.useCallback(()=>{const B=a.current,I=v.current;I&&B===a.current&&Z(kl(I.scrollTop))},[Z,a]),U=()=>{if(A.current!=="")return;if(N.current){N.current=!1;const I=X();x(I);const E=e.indexOf(I);E>=0&&($.current=E);return}x(X()),k.current&&window.clearTimeout(k.current);const B=a.current;k.current=window.setTimeout(()=>{B===a.current&&ee()},100)},J="absolute left-0 right-0 z-40 flex items-center justify-center border-0 bg-transparent p-0 transition-opacity duration-150 hover:opacity-80 focus:outline-none",ce=ht*ho,C=ce+zt*2,_=y!==""?y:null,ae=_!==null;return t.jsxs("div",{ref:g,role:"spinbutton",tabIndex:u?0:-1,"aria-label":i,"aria-valuetext":_??r,"aria-valuenow":d?void 0:Number(r),onFocus:m,onMouseDown:()=>m==null?void 0:m(),onKeyDown:te,onBlur:()=>{D(),A.current!==""&&Q(A.current,!1)},className:"relative shrink-0 rounded-lg outline-none",style:{width:l,height:C,boxShadow:u?"0 0 0 2px color-mix(in srgb, var(--primary) 35%, transparent)":"none"},children:[t.jsx("button",{type:"button","aria-label":"Valor anterior",className:J,style:{top:0,height:zt,color:"var(--text-muted)",opacity:.35},onClick:()=>se(-1),children:t.jsx(q.HiChevronUp,{className:"h-3.5 w-3.5"})}),t.jsx("div",{ref:v,className:"absolute inset-x-0 overflow-y-auto [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden",style:{top:zt,height:ce,scrollSnapType:"y mandatory",scrollBehavior:"auto"},onScroll:U,onMouseUp:ee,onTouchEnd:ee,children:W.map((B,I)=>{const E=B!==""&&B===T;return t.jsx("button",{type:"button",tabIndex:-1,disabled:!B,onClick:()=>{if(!B)return;const oe=e.indexOf(B);oe>=0&&Z(oe)},className:"flex w-full items-center justify-center tabular-nums leading-none disabled:cursor-default",style:{height:ht,scrollSnapAlign:"center",color:E?"var(--text-main)":"var(--text-muted)",fontSize:E?16:14,fontWeight:E?600:400,opacity:B?ae?E?0:.35:E?1:.35:0},children:B},`wheel-${I}-${B}`)})}),_!==null?t.jsx("div",{className:"pointer-events-none absolute inset-x-0 z-50 flex items-center justify-center tabular-nums font-semibold leading-none",style:{top:zt+ce/2-ht/2,height:ht,color:"var(--text-main)",fontSize:16,background:"var(--bg-card)"},children:_}):null,t.jsx("button",{type:"button","aria-label":"Valor siguiente",className:J,style:{bottom:0,height:zt,color:"var(--text-muted)",opacity:.35},onClick:()=>se(1),children:t.jsx(q.HiChevronDown,{className:"h-3.5 w-3.5"})})]})}function Sl(){return t.jsx("span",{className:"flex shrink-0 items-center justify-center self-center text-base font-medium tabular-nums leading-none",style:{color:"var(--text-muted)",height:ht,width:14,opacity:.45},"aria-hidden":!0,children:":"})}function Cl({value:e,onChange:r,use12Hour:n,hour12:a,showSeconds:s=!1,title:l="Seleccionar hora",variant:i="panel",onCancel:c,onConfirm:d,className:u=""}){const m=i==="popover",b=m||!d,f=ff({use12Hour:n,hour12:a}),g=o.useRef(e),v=mo(e,Mr()),k=Kn(v),[h,A]=o.useState(Je(f?k.hour12:v.hour24)),[$,N]=o.useState(Je(v.minute)),[T,x]=o.useState(Je(v.second)),[y,L]=o.useState(k.meridiem),[w,W]=o.useState(0),X=o.useRef(0),Z=o.useRef(!1),D=o.useRef({hour:null,minute:null,second:null,meridiem:null}),[Q,j]=o.useState("hour"),se=o.useMemo(()=>{const ie=["hour","minute"];return s&&ie.push("second"),f&&ie.push("meridiem"),ie},[f,s]),te=o.useCallback(ie=>{j(ge=>{const Me=se.indexOf(ge);return se[(Me+ie+se.length)%se.length]})},[se]);o.useEffect(()=>{var ie;(ie=D.current[Q])==null||ie.focus()},[Q]),o.useEffect(()=>{var ie;j("hour"),(ie=D.current.hour)==null||ie.focus()},[]),o.useEffect(()=>{if(e===g.current)return;g.current=e;const ie=mo(e,Mr()),ge=Kn(ie);A(Je(f?ge.hour12:ie.hour24)),N(Je(ie.minute)),x(Je(ie.second)),L(ge.meridiem)},[f,e]);const ee=o.useMemo(()=>(f?po(1,12):po(0,23)).map(ie=>Je(ie)),[f]),U=o.useMemo(()=>po(0,59).map(ie=>Je(ie)),[]),J=U,ce=o.useMemo(()=>["AM","PM"],[]),C=o.useCallback(()=>f?on({hour12:Number(h),minute:Number($),second:Number(T),meridiem:y}):{hour24:Number(h),minute:Number($),second:Number(T)},[h,f,y,$,T]),_=o.useCallback(ie=>{if(Z.current)return;const ge=an(ie,s);g.current=ge,r(ge)},[r,s]),ae=o.useCallback(()=>{_(C())},[C,_]),B=ie=>{A(ie),b&&_(f?on({hour12:Number(ie),minute:Number($),second:Number(T),meridiem:y}):{hour24:Number(ie),minute:Number($),second:Number(T)})},I=ie=>{N(ie),b&&_(f?on({hour12:Number(h),minute:Number(ie),second:Number(T),meridiem:y}):{hour24:Number(h),minute:Number(ie),second:Number(T)})},E=ie=>{x(ie),b&&_(f?on({hour12:Number(h),minute:Number($),second:Number(ie),meridiem:y}):{hour24:Number(h),minute:Number($),second:Number(ie)})},oe=ie=>{L(ie),b&&_(on({hour12:Number(h),minute:Number($),second:Number(T),meridiem:ie}))},K=o.useCallback(()=>(X.current+=1,W(X.current),X.current),[]),Y=o.useCallback(ie=>{const ge=Kn(ie),Me=an(ie,s);g.current=Me,A(Je(f?ge.hour12:ie.hour24)),N(Je(ie.minute)),x(Je(ie.second)),L(ge.meridiem),r(Me)},[f,r,s]),S=()=>{Z.current=!0,K(),Y(Mr()),queueMicrotask(()=>{const ie=Mr();an(ie,s)!==g.current&&(K(),Y(ie)),Z.current=!1})},H=()=>{ae(),d==null||d()},O=ht*ho,re=O+zt*2,z=zt+O/2-ht/2,de=t.jsx("div",{className:"relative px-4 py-2",children:t.jsxs("div",{className:"relative mx-auto",style:{height:re,maxWidth:"100%"},children:[t.jsx("div",{className:"pointer-events-none absolute inset-x-1 z-10 rounded-xl",style:{top:z,height:ht,background:"color-mix(in srgb, var(--primary) 10%, var(--bg-input))",border:"1px solid color-mix(in srgb, var(--primary) 22%, transparent)"}}),t.jsx("div",{className:"pointer-events-none absolute inset-x-0 z-20",style:{top:zt,height:ht*1.35,background:"linear-gradient(to bottom, var(--bg-card) 40%, transparent 100%)"}}),t.jsx("div",{className:"pointer-events-none absolute inset-x-0 z-20",style:{bottom:zt,height:ht*1.35,background:"linear-gradient(to top, var(--bg-card) 40%, transparent 100%)"}}),t.jsxs("div",{className:"relative z-30 flex h-full items-center justify-center gap-1",children:[t.jsx(Gn,{syncEpochRef:X,forceSyncAt:w,values:ee,selected:h,onSelect:B,label:"Horas",maxNumeric:f?12:23,isFocused:Q==="hour",onFocus:()=>j("hour"),onAdvance:()=>te(1),onBack:()=>te(-1),setColumnRef:ie=>{D.current.hour=ie}}),t.jsx(Sl,{}),t.jsx(Gn,{syncEpochRef:X,forceSyncAt:w,values:U,selected:$,onSelect:I,label:"Minutos",maxNumeric:59,isFocused:Q==="minute",onFocus:()=>j("minute"),onAdvance:()=>te(1),onBack:()=>te(-1),setColumnRef:ie=>{D.current.minute=ie}}),s?t.jsxs(t.Fragment,{children:[t.jsx(Sl,{}),t.jsx(Gn,{syncEpochRef:X,forceSyncAt:w,values:J,selected:T,onSelect:E,label:"Segundos",maxNumeric:59,isFocused:Q==="second",onFocus:()=>j("second"),onAdvance:()=>te(1),onBack:()=>te(-1),setColumnRef:ie=>{D.current.second=ie}})]}):null,f?t.jsx("div",{className:"ml-3 shrink-0 pl-1",children:t.jsx(Gn,{syncEpochRef:X,forceSyncAt:w,values:ce,selected:y,onSelect:ie=>oe(ie),width:uf,label:"AM o PM",isMeridiem:!0,isFocused:Q==="meridiem",onFocus:()=>j("meridiem"),onAdvance:()=>te(1),onBack:()=>te(-1),setColumnRef:ie=>{D.current.meridiem=ie}})}):null]})]})}),he=t.jsxs("div",{className:`flex items-center ${m?"justify-center px-3 py-2":"justify-between gap-2 px-3 py-2.5"}`,style:{borderTop:m?"none":"1px solid color-mix(in srgb, var(--border) 80%, transparent)"},children:[t.jsx(Ue,{variant:"ghost",size:"sm",onClick:S,className:m?"text-xs":void 0,children:"Ahora"}),!m&&(c||d)?t.jsxs("div",{className:"flex items-center gap-2",children:[c?t.jsx(Ue,{variant:"ghost",size:"sm",onClick:c,children:"Cancelar"}):null,d?t.jsx(Ue,{variant:"primary",size:"sm",onClick:H,children:"Listo"}):null]}):null]});return t.jsxs("div",{className:`overflow-hidden ${u}`,style:{borderRadius:m?12:14,border:m?"1px solid color-mix(in srgb, var(--border) 85%, transparent)":"1px solid var(--border)",background:"var(--bg-card)",boxShadow:m?"0 12px 40px rgba(15, 23, 42, 0.14), 0 2px 8px rgba(15, 23, 42, 0.06)":"0 1px 3px rgba(15, 23, 42, 0.06)",minWidth:f?s?300:260:s?252:212},children:[!m&&l?t.jsx("div",{className:"border-b px-3 py-2.5",style:{borderColor:"color-mix(in srgb, var(--border) 80%, transparent)"},children:t.jsx("h3",{className:"text-sm font-semibold",style:{color:"var(--text-main)"},children:l})}):null,de,he]})}function bf(e){return e.use12Hour??e.hour12??!1}function mf({label:e,value:r,onChange:n,use12Hour:a,hour12:s,showSeconds:l=!1,title:i="Seleccionar hora",placeholder:c="Seleccionar hora",disabled:d=!1,displayMode:u="popover",required:m,error:b,helperText:f,helperDisplay:g,className:v,contentClassName:k,className:h=""}){const A=u==="popover",[$,N]=o.useState(!1),T=o.useRef(null),[x,y]=o.useState({horizontal:"left",vertical:"bottom"}),L=bf({use12Hour:a,hour12:s}),w=o.useMemo(()=>r?lf(r,{use12Hour:L,showSeconds:l}):"",[L,l,r]);o.useEffect(()=>{if(!A||!$||!T.current)return;const Z=T.current.getBoundingClientRect(),D=8,Q=L?l?300:260:l?252:212,j=276,se=Z.left+Q>window.innerWidth-D,te=Z.right-Q>=D,ee=Z.bottom+8+j>window.innerHeight-D,U=Z.top-8-j>=D;y({horizontal:se&&te?"right":"left",vertical:ee&&U?"top":"bottom"})},[L,A,$,l]),o.useEffect(()=>{if(!A||!$)return;function Z(Q){T.current&&(T.current.contains(Q.target)||N(!1))}function D(Q){Q.key==="Escape"&&N(!1)}return document.addEventListener("mousedown",Z),document.addEventListener("keydown",D),()=>{document.removeEventListener("mousedown",Z),document.removeEventListener("keydown",D)}},[A,$]);const W=t.jsxs("button",{type:"button",disabled:d,onClick:()=>{d||N(Z=>!Z)},className:`flex h-10 w-full items-center justify-between gap-2 rounded-lg border px-2.5 text-sm transition-all duration-150 focus:outline-none disabled:cursor-not-allowed disabled:opacity-60 ${h}`,style:{background:"var(--bg-input)",borderColor:b?"var(--danger)":$?"var(--primary)":"var(--border)",color:w?"var(--text-main)":"var(--text-muted)",boxShadow:$?"0 0 0 3px color-mix(in srgb, var(--primary) 14%, transparent)":"none"},children:[t.jsxs("span",{className:"inline-flex min-w-0 items-center gap-2",children:[t.jsx(q.HiClock,{className:"h-4 w-4 shrink-0 text-[var(--text-muted)]"}),t.jsx("span",{className:"truncate",children:w||c})]}),A?t.jsx(q.HiChevronDown,{className:`h-4 w-4 shrink-0 text-[var(--text-muted)] transition-transform duration-150 ${$?"rotate-180":""}`}):null]}),X=t.jsx(Cl,{variant:A?"popover":"panel",value:r||cf(l),onChange:n,use12Hour:L,showSeconds:l,title:i,onClose:()=>N(!1)});return t.jsx(In,{label:e,required:m,error:b,helperText:f,helperDisplay:g,className:v,contentClassName:k,children:A?t.jsxs("div",{ref:T,className:"relative w-full",children:[W,$?t.jsx("div",{className:"absolute z-50",style:{...x.horizontal==="left"?{left:0}:{right:0},...x.vertical==="bottom"?{top:"calc(100% + 6px)"}:{bottom:"calc(100% + 6px)"}},children:X}):null]}):t.jsxs("div",{className:"space-y-2",children:[W,$?X:null]})})}const pf={xs:{width:28,height:16,thumb:12,padding:2},sm:{width:36,height:20,thumb:16,padding:2}};function hf({checked:e,disabled:r,onCheckedChange:n,size:a="sm",className:s="",...l}){const i=pf[a],c=e?i.width-i.thumb-i.padding*2:0;return t.jsx("button",{...l,type:"button",role:"switch","aria-checked":e,disabled:r,onClick:()=>!r&&n(!e),className:`relative inline-flex shrink-0 items-center rounded-full transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--primary)]/50 disabled:cursor-not-allowed disabled:opacity-50 ${s}`,style:{width:i.width,height:i.height,background:e?"color-mix(in srgb, var(--primary) 85%, transparent)":"var(--bg-input)",border:e?"1px solid color-mix(in srgb, var(--primary) 55%, transparent)":"1px solid var(--border)"},children:t.jsx("span",{className:"absolute inline-block rounded-full transition-transform",style:{width:i.thumb,height:i.thumb,left:i.padding,top:"50%",transform:`translate(${c}px, -50%)`,background:e?"var(--primary-fg)":"var(--text-muted)"}})})}const El=[".sidebar-scroll",".app-scroll",".showcase-nav-scroll","[data-overlay-scroll='true']"].join(","),gf=[":scope > [data-overlayscrollbars-contents]",":scope > .sidebar-scroll-body",":scope > .showcase-nav-scroll-body",":scope > .app-scroll-body"].join(", ");function vf(e){if(!(e instanceof HTMLElement)||e.dataset.overlayScroll==="false"||e.matches("[data-overlayscrollbars]")||e.closest("[data-overlayscrollbars]")||e.matches("textarea,input,select,[contenteditable='true']"))return!1;const r=window.getComputedStyle(e);return!(![r.overflow,r.overflowX,r.overflowY].join(" ").match(/auto|scroll/)||e.clientWidth===0&&e.clientHeight===0)}function Ml(e){return e.classList.contains("sidebar-scroll")||e.classList.contains("showcase-nav-scroll")}function Tl(e){Ml(e)&&e.querySelectorAll(".os-scrollbar-horizontal").forEach(r=>{r.style.display="none",r.style.height="0",r.style.pointerEvents="none"})}function yf(e){const r=e.querySelector(gf);return r instanceof HTMLElement?r:null}function $l(){return o.useEffect(()=>{const e=new WeakMap;let r=0;const n=()=>{r=0,document.querySelectorAll(El).forEach(l=>{if(!(l instanceof HTMLElement))return;if(Ea.OverlayScrollbars(l)){Tl(l);return}if(!vf(l))return;const c={overflow:Ml(l)?{x:"hidden",y:"scroll"}:void 0,scrollbars:{autoHide:"leave",autoHideDelay:180}},d=yf(l),u=d?Ea.OverlayScrollbars({target:l,elements:{viewport:d}},c):Ea.OverlayScrollbars(l,c);Tl(l),e.set(l,u)})},a=()=>{r||(r=window.requestAnimationFrame(n))};n();const s=new MutationObserver(a);return s.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","data-overlay-scroll"]}),window.addEventListener("resize",a),()=>{r&&window.cancelAnimationFrame(r),s.disconnect(),window.removeEventListener("resize",a),document.querySelectorAll(El).forEach(l=>{var i;l instanceof HTMLElement&&((i=e.get(l))==null||i.destroy())})}},[]),null}function Zt(e){const r=e.trim();return!r||r==="/"||r==="/."?"":(r.startsWith("/")?r:`/${r}`).replace(/\/+$/,"")}function Al(e){try{const r=new URL(e);return Zt(r.pathname)}catch{return""}}function xf(e){const r=Zt(e);if(!r)return"";const n=r.match(/^\/apps\/[^/]+/i);if(n)return Zt(n[0]);const a=r.split("/").filter(Boolean);return a.length===0?"":a.length>=2&&a[0].toLowerCase()==="apps"?Zt(`/${a[0]}/${a[1]}`):new Set(["admin","apps","apps-list","tickets","my-tickets","projects","projects-calendars","dashboard","teams","clients","services","settings","profile","messages","notifications","my-access","my-registers","my-pings","security-incidents","email-inbox","webhook-config","webphone-config","vobo","auth","api","login","forbidden","unauthorized","change-password","reset-password","chat-widget"]).has(a[0].toLowerCase())?"":Zt(`/${a[0]}`)}const go="primeSuiteAppUrl",wf={xs:{wh:"w-5 h-5",text:"text-[8px]"},sm:{wh:"w-7 h-7",text:"text-[11px]"},md:{wh:"w-9 h-9",text:"text-sm"},lg:{wh:"w-12 h-12",text:"text-base"},xl:{wh:"w-16 h-16",text:"text-xl"}},Ll={xs:20,sm:28,md:36,lg:48,xl:64},Dl=["bg-indigo-500","bg-blue-500","bg-emerald-500","bg-violet-500","bg-amber-500","bg-teal-500","bg-rose-500","bg-cyan-500"],Nf={xs:"text-xs",sm:"text-sm",md:"text-base",lg:"text-lg"},kf="bonsaif.bot",Sf="Bonsaif Bot",Cf={xs:"p-0.5",sm:"p-1",md:"p-1.5",lg:"p-2",xl:"p-2.5"};function Il(e){return typeof e=="string"?e.trim():""}function Ef(e){var s;if(e!==void 0)return Zt(e);const r=Zt(typeof process<"u"&&((s=process.env)==null?void 0:s.NEXT_PUBLIC_BASE_PATH)||"");if(r)return r;if(typeof window>"u")return"";try{const i=new URLSearchParams(window.location.search).get(go)||"";i&&window.sessionStorage.setItem(go,i);const c=window.sessionStorage.getItem(go)||"",d=i||c;if(d){const u=Al(d);if(u&&!/^\/admin(\/|$)/i.test(u))return u}}catch{}const n=window.__NEXT_DATA__,a=(n==null?void 0:n.assetPrefix)||"";if(a){const l=a.startsWith("http")?Al(a):Zt(a);if(l&&!/^\/admin(\/|$)/i.test(l))return l}return xf(window.location.pathname)}function Mf(e){const r=e.split(/\s+/).map(n=>n.trim()).filter(Boolean);return r.length===0?"?":r.length===1?r[0].slice(0,1).toUpperCase():`${r[0].slice(0,1)}${r[1].slice(0,1)}`.toUpperCase()}function Tf(e){let r=0;for(const n of e)r=r*31+n.charCodeAt(0)&65535;return Dl[r%Dl.length]}function $f(e,r){return e===kf||r===Sf}function Af(e,r){return`${e.replace(/\/$/,"")}${r}`}function Ol({userId:e,username:r,name:n,size:a="md",showName:s=!1,showTooltip:l,tooltipContent:i,fallbackLabel:c="Usuario",basePath:d,wrapperClassName:u="",labelClassName:m="",labelSize:b="xs",avatarVersion:f=0,className:g="",style:v}){const[k,h]=o.useState(!1),A=typeof e=="string"&&e.trim()&&e!=="undefined"&&e!=="null"?e.trim():"";o.useEffect(()=>{h(!1)},[A,f]);const{wh:$,text:N}=wf[a],T=Il(n)||Il(r)||c,x=Mf(T),y=Ef(d),L=$f(r,n),w=Af(y,"/favicon.svg"),W=o.useMemo(()=>{if(!A)return"";const j=new URLSearchParams;j.set("size",String(Ll[a])),f&&j.set("v",String(f));const se=j.toString();return`${y}/api/user/avatar/${encodeURIComponent(A)}${se?`?${se}`:""}`},[f,y,A,a]),X=Ll[a],Z=L?t.jsx("span",{className:`${$} ${Cf[a]} rounded-full flex items-center justify-center bg-[#071f1a] ring-1 ring-emerald-400/35 shadow-[0_0_0_1px_rgba(255,255,255,0.06)] flex-shrink-0 ${g}`,style:v,children:t.jsx("img",{src:w,alt:T,width:X,height:X,className:"h-full w-full object-contain"})}):W&&!k?t.jsx("img",{src:W,alt:T,width:X,height:X,className:`${$} rounded-full object-cover flex-shrink-0 ${g}`,style:v,loading:"lazy",referrerPolicy:"no-referrer",onError:()=>h(!0)},`${A}-${f}`):t.jsx("span",{className:`${$} ${Tf(T)} ${N} rounded-full flex items-center justify-center font-black text-white uppercase flex-shrink-0 ${g}`,style:v,title:T,children:x});if(s)return t.jsxs("span",{className:`inline-flex min-w-0 items-center gap-2 ${u}`,children:[Z,t.jsx("span",{className:`min-w-0 truncate ${Nf[b]} font-medium text-[var(--text-main)] ${m}`,title:T,children:T})]});const D=l??!0,Q=i??T;return D&&Q?t.jsx(Yt,{as:"span",content:Q,className:`inline-flex flex-shrink-0 ${u}`,children:Z}):Z}function Lf({href:e,className:r,children:n}){return t.jsx("a",{href:e,className:r,children:n})}function Df(e){return e.reduce((r,n)=>{const a=n.section??"Principal";return r[a]=[...r[a]??[],n],r},{})}function Hl({children:e,navItems:r=[],currentPath:n=typeof window>"u"?"/":window.location.pathname,user:a,appName:s="Bonsaif",appLogo:l,header:i,footer:c,onLogout:d,LinkComponent:u=Lf}){const[m,b]=o.useState(!1),f=Df(r);return t.jsxs("div",{className:"min-h-screen bg-[var(--bg-main)] text-[var(--text-main)]",children:[t.jsx($l,{}),t.jsx("button",{type:"button","aria-label":"Abrir navegación",className:"fixed left-3 top-3 z-50 inline-flex h-9 w-9 items-center justify-center rounded-md border border-white/10 bg-black/70 text-white lg:hidden",onClick:()=>b(!0),children:t.jsx(q.HiBars3,{className:"h-5 w-5"})}),m&&t.jsx("button",{type:"button","aria-label":"Cerrar navegación",className:"fixed inset-0 z-40 bg-black/45 lg:hidden",onClick:()=>b(!1)}),t.jsxs("aside",{className:`fixed inset-y-0 left-0 z-50 flex w-72 flex-col bg-[#071716] text-white shadow-2xl transition-transform duration-200 lg:translate-x-0 ${m?"translate-x-0":"-translate-x-full"}`,children:[t.jsxs("div",{className:"flex h-16 items-center gap-3 border-b border-white/10 px-4",children:[t.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-white/10 text-white",children:l??t.jsx(q.HiHome,{className:"h-5 w-5"})}),t.jsx("div",{className:"min-w-0 flex-1 truncate text-sm font-semibold",children:s}),t.jsx("button",{type:"button","aria-label":"Cerrar navegación",className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-white/70 hover:bg-white/10 lg:hidden",onClick:()=>b(!1),children:t.jsx(q.HiXMark,{className:"h-5 w-5"})})]}),t.jsx("nav",{className:"sidebar-scroll min-h-0 flex-1 overflow-y-auto px-3 py-4","data-overlay-scroll":"true",children:t.jsx("div",{className:"sidebar-scroll-body",children:Object.entries(f).map(([g,v])=>t.jsxs("div",{className:"mb-5",children:[t.jsxs("div",{className:"mb-2 flex items-center gap-2 px-2 text-[11px] font-semibold uppercase tracking-wide text-white/35",children:[t.jsx(q.HiChevronDown,{className:"h-3.5 w-3.5"}),g]}),t.jsx("div",{className:"space-y-1",children:v.map(k=>{const h=n===k.href||n.startsWith(`${k.href}/`);return t.jsxs(u,{href:k.href,className:`flex min-w-0 items-center gap-2 rounded-md px-2 py-2 text-sm transition-colors ${h?"bg-white/10 text-white":"text-white/55 hover:bg-white/[0.06] hover:text-white/85"}`,children:[t.jsx("span",{className:"flex h-5 w-5 flex-shrink-0 items-center justify-center",children:k.icon??t.jsx(q.HiHome,{className:"h-4 w-4"})}),t.jsx("span",{className:"truncate",children:k.label})]},k.href)})})]},g))})}),t.jsxs("div",{className:"border-t border-white/10 p-3",children:[a&&t.jsxs("div",{className:"mb-3 flex min-w-0 items-center gap-3 rounded-lg bg-white/[0.04] p-2",children:[t.jsx(Ol,{name:a.initials??a.name??a.email??"Usuario",size:"md"}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"truncate text-sm font-medium text-white",children:a.name??"Usuario"}),a.email&&t.jsx("div",{className:"truncate text-xs text-white/45",children:a.email})]})]}),d&&t.jsxs(Ue,{variant:"ghost",className:"w-full justify-start text-white hover:bg-white/10",onClick:d,children:[t.jsx(q.HiArrowRightOnRectangle,{className:"h-4 w-4"})," Salir"]}),c]})]}),t.jsxs("div",{className:"min-h-screen lg:pl-72",children:[i,t.jsx("main",{className:"min-h-screen",children:e})]})]})}const Bl="bonsaif-ui:prime-auth-sso",If={dashboard:"Dashboard",tickets:"Tickets",teams:"Equipos",projects:"Proyectos",clients:"Clientes",surveys:"Encuestas",profile:"Perfil",settings:"Configuración",notifications:"Notificaciones",changelog:"Historial",admin:"Inicio",users:"Usuarios",roles:"Roles",menus:"Menús",guards:"Guardias",vacations:"Vacaciones",audit:"Auditoría",positions:"Puestos",ranks:"Rangos","email-inbox":"Buzones","security-incidents":"Incidentes","guard-schedule":"Guardias"},vo={dashboard:t.jsx(q.HiChartBar,{className:"h-5 w-5"}),tickets:t.jsx(q.HiTicket,{className:"h-5 w-5"}),teams:t.jsx(q.HiUsers,{className:"h-5 w-5"}),projects:t.jsx(q.HiRectangleGroup,{className:"h-5 w-5"}),clients:t.jsx(q.HiBuildingOffice2,{className:"h-5 w-5"}),surveys:t.jsx(q.HiClipboardDocumentList,{className:"h-5 w-5"}),profile:t.jsx(q.HiUser,{className:"h-5 w-5"}),settings:t.jsx(q.HiCog6Tooth,{className:"h-5 w-5"}),notifications:t.jsx(q.HiBell,{className:"h-5 w-5"}),changelog:t.jsx(q.HiDocumentText,{className:"h-5 w-5"}),admin:t.jsx(q.HiShieldCheck,{className:"h-5 w-5"}),users:t.jsx(q.HiUsers,{className:"h-5 w-5"}),roles:t.jsx(q.HiShieldCheck,{className:"h-5 w-5"}),menus:t.jsx(q.HiCog6Tooth,{className:"h-5 w-5"}),guards:t.jsx(q.HiCalendarDays,{className:"h-5 w-5"}),vacations:t.jsx(q.HiCalendarDays,{className:"h-5 w-5"}),audit:t.jsx(q.HiListBullet,{className:"h-5 w-5"}),positions:t.jsx(q.HiBriefcase,{className:"h-5 w-5"}),ranks:t.jsx(q.HiListBullet,{className:"h-5 w-5"}),"email-inbox":t.jsx(q.HiInbox,{className:"h-5 w-5"}),"security-incidents":t.jsx(q.HiShieldCheck,{className:"h-5 w-5"})};function Of(e){return e.split("-").map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" ")}function Hf(e){return/^\d+$/.test(e)||/^[a-f0-9]{8,}$/i.test(e)}function Bf(e){const r=e.split("/").filter(Boolean);if(r.length===0||r.length===1&&r[0]==="dashboard")return[];const n=decodeURIComponent(r[r.length-1]),a=r.length>1?decodeURIComponent(r[r.length-2]):void 0,s=Hf(n)&&a?a:n,l=If[s]??Of(s);return[{label:"Inicio",href:"/"},{label:l}]}function yo(e){return(e==null?void 0:e.querySelector(":scope > .os-viewport"))??(e==null?void 0:e.querySelector(":scope > [data-overlayscrollbars-viewport]"))}function Ff(e){const r=e.split("/").filter(Boolean),n=r[r.length-1];if(!n)return t.jsx(q.HiHome,{className:"h-5 w-5"});if(vo[n])return vo[n];const a=r.length>1?r[r.length-2]:"";return vo[a]??t.jsx(q.HiHome,{className:"h-5 w-5"})}function Pf(e){return e.includes("primeAuthOrigin")||e.includes("primeAuthProjectKey")}function Fl(){if(typeof window>"u")return!1;if(Pf(window.location.href)){try{window.sessionStorage.setItem(Bl,"true")}catch{}return!0}try{return window.sessionStorage.getItem(Bl)==="true"}catch{return!1}}function _f({title:e,subtitle:r,action:n,meta:a,icon:s,className:l="",contentClassName:i="",breadcrumbs:c,currentPath:d,showBreadcrumbs:u=!0,contained:m=!1}){const b=o.useRef(null),[f,g]=o.useState(!1),[v,k]=o.useState(d??"/"),[h,A]=o.useState(()=>Fl()),[$,N]=o.useState(null),T=d??v,x=c??Bf(T),y=s??Ff(T),L=u&&!h&&x.length>1,w=!L;o.useEffect(()=>{d||k(window.location.pathname)},[d]),o.useEffect(()=>{A(Fl())},[]),o.useEffect(()=>{if(m){g(!1);return}let X=null,Z=0,D=0;const Q=()=>{const te=b.current,ee=document.querySelector("[data-app-scroll='true']");return(te==null?void 0:te.closest(".os-viewport"))??(te==null?void 0:te.closest("[data-overlayscrollbars-viewport]"))??yo(ee)??ee??window},j=()=>{const te=X&&X!==window?X.scrollTop:window.scrollY;g(ee=>ee?te>24:te>72)},se=()=>{X==null||X.removeEventListener("scroll",j),X=Q(),X.addEventListener("scroll",j,{passive:!0}),j()};return se(),Z=window.requestAnimationFrame(se),D=window.setTimeout(se,120),()=>{window.cancelAnimationFrame(Z),window.clearTimeout(D),X==null||X.removeEventListener("scroll",j)}},[m]),o.useEffect(()=>{if(m){N(null);return}let X=0;const Z=[],D=()=>{const J=b.current,ce=J==null?void 0:J.parentElement,C=document.querySelector("[data-app-scroll='true']"),_=yo(C)??C;if(!J||!ce||!_){N(null);return}const ae=ce.getBoundingClientRect(),B=window.getComputedStyle(ce),I=_.getBoundingClientRect(),E=_ instanceof HTMLElement&&_.clientWidth>0?_.clientWidth:I.width,oe=ae.left+parseFloat(B.paddingLeft||"0"),K={marginLeft:Math.round(I.left-oe),width:Math.round(E)};N(Y=>Y&&Y.marginLeft===K.marginLeft&&Y.width===K.width?Y:K)},Q=()=>{window.cancelAnimationFrame(X),X=window.requestAnimationFrame(D)};Q(),window.addEventListener("resize",Q);const j=new ResizeObserver(Q),se=b.current,te=se==null?void 0:se.parentElement,ee=document.querySelector("[data-app-scroll='true']"),U=yo(ee)??ee;return[te,ee,U].forEach(J=>{J&&j.observe(J)}),Z.push(window.setTimeout(Q,120)),Z.push(window.setTimeout(Q,280)),()=>{window.cancelAnimationFrame(X),window.removeEventListener("resize",Q),j.disconnect(),Z.forEach(J=>window.clearTimeout(J))}},[m]);const W={...$?{marginLeft:$.marginLeft,width:$.width}:null,"--page-header-control-height":f?"34px":"40px","--page-header-control-padding-x":f?"10px":"14px","--page-header-control-icon-left":f?"10px":"12px",background:m?"var(--bg-card)":f?"color-mix(in srgb, var(--bg-main) 82%, transparent)":"color-mix(in srgb, var(--bg-main) 58%, transparent)",backdropFilter:"saturate(1.25) blur(18px)",WebkitBackdropFilter:"saturate(1.25) blur(18px)",borderBottom:m||f?"1px solid var(--border)":"1px solid transparent",boxShadow:f?"0 10px 28px rgba(12, 54, 53, 0.12)":"none"};return t.jsx("div",{ref:b,"data-page-header":"true","data-compact":f?"true":"false",className:`sticky top-0 z-30 overflow-visible py-0 transition-[background-color,box-shadow,border-color] duration-300 ease-out ${m?"mb-0 flex-shrink-0":"mb-4 sm:mb-0"} ${l}`,style:W,children:t.jsxs("div",{className:`flex flex-wrap items-center justify-between transition-[gap,min-height,padding] duration-300 ease-out ${f?"min-h-8 gap-1.5 px-3 py-0 sm:min-h-9 sm:gap-2":w?"min-h-9 gap-2 px-4 py-0 sm:min-h-10 sm:gap-2.5":"min-h-10 gap-2.5 px-4 pt-0.5 sm:min-h-11 sm:gap-3"} ${i}`,children:[t.jsx("div",{className:`min-w-0 flex flex-1 flex-col justify-center transition-[gap,transform] duration-300 ease-out ${f||w?"gap-1":"gap-1.5 sm:gap-2"}`,children:t.jsxs("div",{className:`flex min-w-0 items-center transition-[gap,transform] duration-300 ease-out ${f||w?"gap-2":"gap-2.5 sm:gap-3"}`,children:[t.jsx("span",{className:`flex-shrink-0 transition-[color,transform,opacity] duration-300 ease-out ${f?"scale-75 opacity-80":"scale-90 opacity-100"}`,style:{color:L?"var(--text-secondary)":"var(--text-muted)"},children:y}),t.jsxs("div",{className:`flex min-w-0 flex-1 flex-wrap items-center transition-[gap] duration-300 ease-out ${f?"gap-x-2 gap-y-1":"gap-x-3 gap-y-2"}`,children:[t.jsxs("div",{className:"min-w-0 flex-shrink transition-[transform] duration-300 ease-out",children:[t.jsx("h1",{className:`truncate font-bold tracking-tight transition-[font-size,line-height,color] duration-300 ease-out ${f?"text-sm sm:text-base":"text-lg sm:text-xl"}`,style:{color:"var(--text-main)"},children:e}),r&&t.jsx("div",{"aria-hidden":f,className:`overflow-hidden text-xs transition-[max-height,opacity,transform,margin] duration-300 ease-out ${f?"mt-0 max-h-0 -translate-y-1 opacity-0":"mt-0.5 max-h-8 translate-y-0 opacity-100"}`,style:{color:"var(--text-muted)"},children:r})]}),a&&t.jsx("div",{className:`page-header-meta flex min-w-0 flex-1 basis-full items-center overflow-visible transition-[gap,opacity,transform] duration-300 ease-out sm:basis-auto ${f?"translate-y-0 gap-1.5 opacity-95":"gap-2 opacity-100"}`,children:a})]})]})}),n&&t.jsx("div",{className:`page-header-actions ml-auto flex max-w-full flex-shrink-0 flex-wrap items-center justify-end self-center overflow-visible transition-[gap,min-height,opacity,transform] duration-300 ease-out ${f?"min-h-9 gap-1 opacity-95":"min-h-9 gap-1.5 opacity-100"}`,children:t.jsx(jo.Provider,{value:{compact:!0,headerAction:!0},children:n})})]})})}function zf({children:e,currentPath:r=typeof window>"u"?"/":window.location.pathname,publicRoutes:n=["/","/login","/reset-password"],...a}){return n.includes(r)?t.jsx(t.Fragment,{children:e}):t.jsx(Hl,{currentPath:r,...a,children:e})}function Pl(){if(typeof window>"u")return"system";const e=localStorage.getItem("theme");return e==="light"||e==="dark"?e:e==="system"?"system":document.documentElement.classList.contains("dark")?"dark":"light"}function Wf(e,r,n){try{const a=new URL(e),s=a.searchParams.get("callbackUrl");if(s){const l=new URL(s,a.origin);return l.searchParams.set("theme",r),n&&(l.searchParams.set("primeAuthOrigin",window.location.origin),l.searchParams.set("primeAuthProjectKey",n)),a.searchParams.set("callbackUrl",`${l.pathname}${l.search}${l.hash}`),a.toString()}return a.searchParams.set("theme",r),n&&(a.searchParams.set("primeAuthOrigin",window.location.origin),a.searchParams.set("primeAuthProjectKey",n)),a.toString()}catch{return e}}function jf({name:e,src:r,projectKey:n}){const[a,s]=o.useState("system"),l=o.useRef(null);o.useEffect(()=>{s(Pl());const d=new MutationObserver(()=>s(Pl()));return d.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>d.disconnect()},[]);const i=o.useMemo(()=>Wf(r,a,n),[n,r,a]),c=o.useMemo(()=>{try{return new URL(i).origin}catch{return""}},[i]);return o.useEffect(()=>{if(!n)return;const d=n;function u(m){var g,v,k;if(m.source!==((g=l.current)==null?void 0:g.contentWindow)||c&&m.origin!==c)return;if(((v=m.data)==null?void 0:v.type)==="prime-microservice:overlay"){window.dispatchEvent(new CustomEvent("prime-auth:microservice-overlay",{detail:{active:!!m.data.active}}));return}if(((k=m.data)==null?void 0:k.type)!=="prime-microservice:navigation")return;const b=m.data.path;if(!b||!b.startsWith("/")||b.startsWith("//"))return;const f=`/apps/${encodeURIComponent(d)}${b}`;`${window.location.pathname}${window.location.search}${window.location.hash}`!==f&&(window.history.replaceState(window.history.state,"",f),window.dispatchEvent(new CustomEvent("prime-auth:microservice-navigation")))}return window.addEventListener("message",u),()=>{window.removeEventListener("message",u),window.dispatchEvent(new CustomEvent("prime-auth:microservice-overlay",{detail:{active:!1}}))}},[c,n]),t.jsx("div",{className:"flex h-full min-h-screen flex-col bg-[var(--bg-main)]",children:t.jsx("iframe",{ref:l,src:i,title:e,className:"min-h-0 flex-1 border-0 bg-[var(--bg-main)]",allow:"clipboard-write",sandbox:"allow-downloads allow-forms allow-modals allow-popups allow-same-origin allow-scripts",referrerPolicy:"strict-origin-when-cross-origin"})})}function qf(){const[e,r]=o.useState(""),[n,a]=o.useState(!1),[s,l]=o.useState({width:96,height:96});return o.useEffect(()=>{let i=!1;return fetch("/api/microservices/prime-suite/chat-url",{cache:"no-store"}).then(c=>c.ok?c.json():null).then(c=>{!i&&(c!=null&&c.src)&&r(c.src)}).catch(()=>{}),()=>{i=!0}},[]),o.useEffect(()=>{const i=c=>{var u;if(((u=c.data)==null?void 0:u.type)!=="prime-suite-chat:state")return;const d=!!c.data.active;a(d),l({width:_l(c.data.width,96,720),height:_l(c.data.height,96,560)})};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)},[]),e?t.jsx("iframe",{title:"Chat Bonsaif",src:e,allow:"clipboard-write",className:"fixed bottom-0 right-0 z-[70] border-0 bg-transparent transition-[width,height] duration-200",style:{width:n?`min(${s.width}px, 100vw)`:96,height:n?`min(${s.height}px, 100vh)`:96,background:"transparent",backgroundColor:"transparent",colorScheme:"normal"}}):null}function _l(e,r,n){const a=typeof e=="number"&&Number.isFinite(e)?e:r;return Math.max(r,Math.min(n,Math.ceil(a)))}function Uf(e){const r=document.documentElement,n=new MutationObserver(e);n.observe(r,{attributes:!0,attributeFilter:["class"]});const a=window.matchMedia("(prefers-color-scheme: dark)");return a.addEventListener("change",e),()=>{n.disconnect(),a.removeEventListener("change",e)}}function Vf(){const e=localStorage.getItem("theme")||"system",r=window.matchMedia("(prefers-color-scheme: dark)").matches;return document.documentElement.classList.contains("dark")||e==="dark"||e==="system"&&r?"dark":"light"}function Yf(){return"light"}function Xf({position:e="bottom-center"}){const r=o.useSyncExternalStore(Uf,Vf,Yf);return t.jsx(Ma.Toaster,{position:e,theme:r,richColors:!0,closeButton:!0})}function Kf({title:e,subtitle:r,actions:n,loading:a=!1,empty:s=!1,emptyText:l="Sin datos para mostrar",className:i="",children:c}){return t.jsxs("div",{className:`bonsaif-chart-card w-full overflow-visible ${i}`,children:[(e||r||n)&&t.jsxs("div",{className:"bonsaif-chart-card-head",children:[t.jsx("div",{className:"bonsaif-chart-card-accent","aria-hidden":!0}),t.jsxs("div",{className:"bonsaif-chart-card-copy min-w-0",children:[e?t.jsx("div",{className:"bonsaif-chart-card-title",children:e}):null,r?t.jsx("div",{className:"bonsaif-chart-card-subtitle",children:r}):null]}),n?t.jsx("div",{className:"bonsaif-chart-card-actions shrink-0",children:n}):null]}),t.jsx("div",{className:"bonsaif-chart-card-body",children:a?t.jsx("div",{className:"flex h-48 items-center justify-center",children:t.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-2 border-t-transparent",style:{borderColor:"var(--border)",borderTopColor:"var(--primary)"},"aria-label":"Cargando"})}):s?t.jsx("div",{className:"flex h-48 items-center justify-center text-sm",style:{color:"var(--text-muted)"},children:l}):c})]})}const sn=["var(--primary)","#38bdf8","#34d399","#a78bfa","#2dd4bf","#fbbf24","#60a5fa","#94a3b8"];function zl(e,r){return e.color??sn[r%sn.length]}function Lt(e="primary"){switch(e){case"success":return"#34d399";case"warning":return"#fbbf24";case"danger":return"#f87171";case"neutral":return"var(--text-muted)";default:return"var(--primary)"}}const gt=e=>{if(!Number.isFinite(e))return"—";const r=Math.abs(e);return r>=1e9?`${(e/1e9).toFixed(1).replace(/\.0$/,"")}B`:r>=1e6?`${(e/1e6).toFixed(1).replace(/\.0$/,"")}M`:r>=1e4?`${(e/1e3).toFixed(1).replace(/\.0$/,"")}k`:e.toLocaleString(void 0,{maximumFractionDigits:2})};function Tr(e){if(e==null||e==="")return null;const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?r:null}const xo={warning:70,danger:90};function Zn(e,r=xo){const n=r.warning??xo.warning,a=r.danger??xo.danger;return e>=a?"danger":e>=n?"warning":e<=0?"primary":"success"}function ln(e,r){return Lt(Zn(e,r))}function $r(e,r=0){return Number.isFinite(e)?`${e.toFixed(r)}%`:"—"}function Ar(e,r=1){if(!Number.isFinite(e))return"—";const n=e<0?"-":"",a=Math.abs(e);if(a<1024)return`${n}${Math.round(a)} B`;const s=["KB","MB","GB","TB","PB"];let l=a/1024,i=0;for(;l>=1024&&i<s.length-1;)l/=1024,i+=1;const c=l>=100?l.toFixed(0):l.toFixed(r);return`${n}${c.replace(/\.0$/,"")} ${s[i]}`}function Wl(e,r="bytes",n=1){if(!Number.isFinite(e))return"—";const a=e<0?"-":"",s=Math.abs(e),l=r==="bits"?["b/s","Kb/s","Mb/s","Gb/s","Tb/s"]:["B/s","KB/s","MB/s","GB/s","TB/s"];if(s<1024)return`${a}${Math.round(s)} ${l[0]}`;let i=s/1024,c=1;for(;i>=1024&&c<l.length-1;)i/=1024,c+=1;const d=i>=100?i.toFixed(0):i.toFixed(n);return`${a}${d.replace(/\.0$/,"")} ${l[c]}`}function Lr(e,r){var n;for(let a=e.length-1;a>=0;a-=1){const s=Tr((n=e[a])==null?void 0:n[r]);if(s!==null)return s}return null}function vt({height:e}){return t.jsx("div",{className:"flex items-center justify-center",style:{height:e},"aria-busy":!0,children:t.jsx("div",{className:"h-7 w-7 animate-spin rounded-full border-2",style:{borderColor:"var(--border)",borderTopColor:"var(--primary)"}})})}function yt({height:e,text:r}){return t.jsx("div",{className:"flex items-center justify-center text-sm",style:{height:e,color:"var(--text-muted)"},children:r})}const Qt=680,sr="ease-out",Gf={top:18,right:8,bottom:12,left:0};function cn(e){return{...Gf,...e}}function dn(e){return e.map((r,n)=>({...r,color:zl(r,n),label:r.label??r.key}))}function Qn(e,r){return!e.length||!r.length||e.every(n=>r.every(a=>Tr(n[a.key])===null))}function xt(){return{fill:"var(--text-muted)",fontSize:10,fontWeight:500,letterSpacing:"0.02em"}}function un(){return"color-mix(in srgb, var(--border) 55%, transparent)"}function jl(){return"color-mix(in srgb, var(--primary) 45%, var(--border))"}function Jn(){return{paddingBottom:12,paddingLeft:4,fontSize:11,fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"var(--text-muted)"}}function Zf(e,r=gt){if(e==null||e==="")return"—";const n=typeof e=="number"?e:Number(e);return Number.isFinite(n)?r(n):String(e)}function ql(e){return`bonsaif-grad-${e.replace(/[^a-zA-Z0-9_-]/g,"")}`}function Qf({active:e,label:r,payload:n,valueFormat:a=gt}){var c,d,u,m,b,f;if(!e||!(n!=null&&n.length))return null;const s=n.filter(g=>g.dataKey!=="base"&&g.name!=="base"&&g.value!==null&&g.value!==void 0);if(!s.length)return null;const l=((d=(c=s[0])==null?void 0:c.payload)==null?void 0:d.fullName)??((m=(u=s[0])==null?void 0:u.payload)==null?void 0:m.tooltipLabel)??((f=(b=s[0])==null?void 0:b.payload)==null?void 0:f.display),i=typeof l=="string"&&l.length>0?l:r;return t.jsxs("div",{className:"bonsaif-chart-tooltip-panel",children:[i!=null&&i!==""?t.jsx("div",{className:"bonsaif-chart-tooltip-label",children:String(i)}):null,t.jsx("div",{className:"bonsaif-chart-tooltip-items",children:s.map((g,v)=>{const k=g.payload,h=k&&typeof k.display=="number"?k.display:g.value;return t.jsxs("div",{className:"bonsaif-chart-tooltip-row",children:[t.jsxs("span",{className:"bonsaif-chart-tooltip-name",children:[t.jsx("span",{className:"bonsaif-chart-tooltip-swatch",style:{background:g.color??"var(--primary)"}}),g.name??g.dataKey]}),t.jsx("span",{className:"bonsaif-chart-tooltip-value",children:Zf(h,a)})]},String(g.dataKey??g.name??v))})})]})}function Dr({valueFormat:e,content:r,cursor:n,offset:a=12,wrapperStyle:s,allowEscapeViewBox:l,reverseDirection:i,...c}){return t.jsx(Se.Tooltip,{...c,cursor:n,offset:a,allowEscapeViewBox:l??{x:!1,y:!1},reverseDirection:i??{x:!1,y:!1},wrapperStyle:{outline:"none",zIndex:60,pointerEvents:"none",overflow:"visible",...s},content:r??t.jsx(Qf,{valueFormat:e})})}function Ul(e,r,n){return n==null?-1:e.findIndex(a=>String(a[r])===String(n))}function Vl(e,r,n){if(n<=1)return null;const a=Math.max(0,Math.min(e,r)),s=Math.min(n-1,Math.max(e,r));return s-a<1||a===0&&s>=n-1?null:{startIndex:a,endIndex:s}}function Rn(e,r,n={}){const{zoomable:a=!1,zoomMode:s="both",brushHeight:l=28,onZoomChange:i}=n,[c,d]=o.useState(null),[u,m]=o.useState(null),b=!!a&&e.length>1,f=b&&(s==="brush"||s==="both"),g=b&&(s==="drag"||s==="both"),v=o.useCallback(Z=>{d(Z),i==null||i(Z)},[i]),k=o.useCallback(()=>{m(null),v(null)},[v]),h=!!c,A=o.useMemo(()=>!c||f?e:e.slice(c.startIndex,c.endIndex+1),[e,f,c]),$=o.useCallback((Z,D)=>{const Q=Ul(e,r,Z),j=Ul(e,r,D);Q<0||j<0||v(Vl(Q,j,e.length))},[v,e,r]),N=o.useCallback(Z=>{g&&((Z==null?void 0:Z.activeLabel)===void 0||(Z==null?void 0:Z.activeLabel)===null||m({leftLabel:Z.activeLabel,rightLabel:Z.activeLabel}))},[g]),T=o.useCallback(Z=>{!g||!u||(Z==null?void 0:Z.activeLabel)===void 0||(Z==null?void 0:Z.activeLabel)===null||m(D=>D&&{...D,rightLabel:Z.activeLabel})},[u,g]),x=o.useCallback(()=>{if(g){if(!u||u.rightLabel===null||u.rightLabel===void 0){m(null);return}$(u.leftLabel,u.rightLabel),m(null)}},[$,u,g]),y=o.useCallback(Z=>{if(f){if(!Z){v(null);return}v(Vl(Z.startIndex??0,Z.endIndex??e.length-1,e.length))}},[v,e.length,f]),L=g?{onMouseDown:N,onMouseMove:T,onMouseUp:x,onMouseLeave:()=>{u&&x()}}:{},w=c??{startIndex:0,endIndex:Math.max(0,e.length-1)},W=t.jsxs(t.Fragment,{children:[g&&u&&u.rightLabel!==null&&u.rightLabel!==void 0?t.jsx(Se.ReferenceArea,{x1:u.leftLabel,x2:u.rightLabel,strokeOpacity:.18,fill:"var(--primary)",fillOpacity:.12,stroke:"var(--primary)"}):null,f?t.jsx(Se.Brush,{dataKey:r,height:l,stroke:"var(--primary)",fill:"color-mix(in srgb, var(--primary) 10%, var(--bg-card))",travellerWidth:8,startIndex:w.startIndex,endIndex:w.endIndex,onChange:y,tickFormatter:Z=>String(Z)}):null]}),X=f?{bottom:Math.max(l+10,36)}:void 0;return{enabled:b,showBrush:f,showDrag:g,viewData:A,isZoomed:h,resetZoom:k,chartHandlers:L,zoomNodes:W,marginExtra:X}}function ea({visible:e,onReset:r}){return e?t.jsx("button",{type:"button",className:"bonsaif-chart-zoom-reset",onClick:r,"aria-label":"Restablecer zoom",children:"Restablecer zoom"}):null}function Jf({data:e,xKey:r,series:n,height:a=280,className:s="",loading:l=!1,emptyText:i="Sin datos para mostrar",showGrid:c=!0,showLegend:d=!0,showTooltip:u=!0,margin:m,valueFormat:b=gt,yDomain:f,ariaLabel:g="Gráfico de líneas",curve:v=!0,strokeWidth:k=2.25,zoomable:h=!1,zoomMode:A="both",brushHeight:$,onZoomChange:N}){const T=Qn(e,n),x=dn(n),y=Rn(e,r,{zoomable:h,zoomMode:A,brushHeight:$,onZoomChange:N}),L=cn({...m,...y.marginExtra});return l?t.jsx(vt,{height:a}):T?t.jsx(yt,{height:a,text:i}):t.jsxs("div",{className:`bonsaif-chart bonsaif-line-chart w-full ${s}`,role:"img","aria-label":g,style:{height:a},children:[t.jsx(ea,{visible:y.isZoomed,onReset:y.resetZoom}),t.jsx(Se.ResponsiveContainer,{width:"100%",height:"100%",children:t.jsxs(Se.LineChart,{data:y.viewData,margin:L,...y.chartHandlers,children:[c?t.jsx(Se.CartesianGrid,{strokeDasharray:"2 8",stroke:un(),vertical:!1}):null,t.jsx(Se.XAxis,{dataKey:r,tick:xt(),tickLine:!1,axisLine:!1,padding:{left:0,right:0},interval:"preserveStartEnd",minTickGap:52,dy:6}),t.jsx(Se.YAxis,{tick:xt(),tickLine:!1,axisLine:!1,width:44,domain:f??["auto","auto"],tickFormatter:w=>b(Number(w)),dx:-2}),u?t.jsx(Dr,{valueFormat:b,cursor:{stroke:jl(),strokeWidth:1.25,strokeDasharray:"4 4"}}):null,d?t.jsx(Se.Legend,{verticalAlign:"top",align:"right",iconType:"circle",iconSize:7,wrapperStyle:Jn()}):null,x.map((w,W)=>t.jsx(Se.Line,{type:v?"monotone":"linear",dataKey:w.key,name:w.label,stroke:w.color,strokeWidth:W===0?k+.35:k,strokeOpacity:W===0?1:.88,isAnimationActive:!0,animationDuration:Qt,animationEasing:sr,dot:!1,activeDot:{r:5,strokeWidth:2,stroke:"var(--bg-card)",fill:w.color}},w.key)),y.zoomNodes]})})]})}function ta({data:e,xKey:r,series:n,height:a=280,className:s="",loading:l=!1,emptyText:i="Sin datos para mostrar",showGrid:c=!0,showLegend:d=!0,showTooltip:u=!0,margin:m,valueFormat:b=gt,yDomain:f,ariaLabel:g="Gráfico de área",stacked:v=!1,opacity:k=.22,zoomable:h=!1,zoomMode:A="both",brushHeight:$,onZoomChange:N}){const T=Qn(e,n),x=dn(n),y=Rn(e,r,{zoomable:h,zoomMode:A,brushHeight:$,onZoomChange:N}),L=cn({...m,...y.marginExtra});return l?t.jsx(vt,{height:a}):T?t.jsx(yt,{height:a,text:i}):t.jsxs("div",{className:`bonsaif-chart bonsaif-area-chart w-full ${s}`,role:"img","aria-label":g,style:{height:a},children:[t.jsx(ea,{visible:y.isZoomed,onReset:y.resetZoom}),t.jsx(Se.ResponsiveContainer,{width:"100%",height:"100%",children:t.jsxs(Se.AreaChart,{data:y.viewData,margin:L,...y.chartHandlers,children:[t.jsx("defs",{children:x.map(w=>t.jsxs("linearGradient",{id:ql(w.key),x1:"0",y1:"0",x2:"0",y2:"1",children:[t.jsx("stop",{offset:"0%",stopColor:w.color,stopOpacity:Math.min(.55,k+.28)}),t.jsx("stop",{offset:"48%",stopColor:w.color,stopOpacity:k*.5}),t.jsx("stop",{offset:"100%",stopColor:w.color,stopOpacity:0})]},w.key))}),c?t.jsx(Se.CartesianGrid,{strokeDasharray:"2 8",stroke:un(),vertical:!1}):null,t.jsx(Se.XAxis,{dataKey:r,tick:xt(),tickLine:!1,axisLine:!1,padding:{left:0,right:0},interval:"preserveStartEnd",minTickGap:52,dy:6}),t.jsx(Se.YAxis,{tick:xt(),tickLine:!1,axisLine:!1,width:44,domain:f??["auto","auto"],tickFormatter:w=>b(Number(w)),dx:-2}),u?t.jsx(Dr,{valueFormat:b,cursor:{stroke:jl(),strokeWidth:1.25,strokeDasharray:"4 4"}}):null,d?t.jsx(Se.Legend,{verticalAlign:"top",align:"right",iconType:"circle",iconSize:7,wrapperStyle:Jn()}):null,x.map(w=>t.jsx(Se.Area,{type:"monotone",dataKey:w.key,name:w.label,stroke:w.color,fill:`url(#${ql(w.key)})`,strokeWidth:2.25,stackId:v?"stack":void 0,isAnimationActive:!0,animationDuration:Qt,animationEasing:sr,dot:!1,activeDot:{r:5,strokeWidth:2,stroke:"var(--bg-card)",fill:w.color}},w.key)),y.zoomNodes]})})]})}function Rf({data:e,xKey:r,series:n,height:a=280,className:s="",loading:l=!1,emptyText:i="Sin datos para mostrar",showGrid:c=!0,showLegend:d=!0,showTooltip:u=!0,margin:m,valueFormat:b=gt,yDomain:f,ariaLabel:g="Gráfico de barras",layout:v="vertical",mode:k="grouped",barRadius:h=6,categoryAxisWidth:A=64,zoomable:$=!1,zoomMode:N="both",brushHeight:T,onZoomChange:x}){const y=Qn(e,n),L=dn(n),w=v==="horizontal",W=Rn(e,r,{zoomable:$&&!w,zoomMode:N,brushHeight:T,onZoomChange:x}),X=cn({...m,...W.marginExtra});return l?t.jsx(vt,{height:a}):y?t.jsx(yt,{height:a,text:i}):t.jsxs("div",{className:`bonsaif-chart bonsaif-bar-chart w-full ${s}`,role:"img","aria-label":g,style:{height:a},children:[t.jsx(ea,{visible:W.isZoomed,onReset:W.resetZoom}),t.jsx(Se.ResponsiveContainer,{width:"100%",height:"100%",children:t.jsxs(Se.BarChart,{data:W.viewData,margin:X,layout:w?"vertical":"horizontal",barCategoryGap:"34%",barGap:3,...W.chartHandlers,children:[c?t.jsx(Se.CartesianGrid,{strokeDasharray:"2 8",stroke:un(),horizontal:!w,vertical:w}):null,w?t.jsxs(t.Fragment,{children:[t.jsx(Se.XAxis,{type:"number",tick:xt(),tickLine:!1,axisLine:!1,tickFormatter:Z=>b(Number(Z)),domain:f??["auto","auto"]}),t.jsx(Se.YAxis,{type:"category",dataKey:r,tick:xt(),tickLine:!1,axisLine:!1,width:A})]}):t.jsxs(t.Fragment,{children:[t.jsx(Se.XAxis,{dataKey:r,tick:xt(),tickLine:!1,axisLine:!1,interval:"preserveStartEnd",minTickGap:36,dy:6}),t.jsx(Se.YAxis,{tick:xt(),tickLine:!1,axisLine:!1,width:44,domain:f??["auto","auto"],tickFormatter:Z=>b(Number(Z)),dx:-2})]}),u?t.jsx(Dr,{valueFormat:b,cursor:{fill:"color-mix(in srgb, var(--primary) 8%, transparent)"}}):null,d?t.jsx(Se.Legend,{verticalAlign:"top",align:"right",iconType:"circle",iconSize:7,wrapperStyle:Jn()}):null,L.map((Z,D)=>t.jsx(Se.Bar,{dataKey:Z.key,name:Z.label,fill:Z.color,fillOpacity:D===0?1:.82,radius:w?[0,h,h,0]:[h,h,2,2],maxBarSize:20,stackId:k==="stacked"?"stack":void 0,isAnimationActive:!0,animationDuration:Qt,animationEasing:sr},Z.key)),W.zoomNodes]})})]})}function eb(e){return t.jsx(Xl,{...e,variant:"pie"})}function tb(e){return t.jsx(Xl,{...e,variant:"donut",innerRadius:e.innerRadius??.62,cornerRadius:e.cornerRadius??10,padAngle:e.padAngle??2})}function Yl(e,r){return e==null||!Number.isFinite(e)?r:e>0&&e<=1?e*100:e}function Xl({data:e,nameKey:r,valueKey:n,height:a=280,className:s="",loading:l=!1,emptyText:i="Sin datos para mostrar",showLegend:c=!0,showTooltip:d=!0,valueFormat:u=gt,ariaLabel:m,innerRadius:b,outerRadius:f,colors:g=[...sn],padAngle:v,cornerRadius:k,variant:h}){const A=e.map((D,Q)=>({name:String(D[r]??""),value:Tr(D[n])??0,fill:g[Q%g.length],row:D})).filter(D=>D.value>0),$=!A.length,N=h==="donut",T=A.length,x=Yl(b,N?62:12),y=Yl(f,78),L=Math.min(v??(N?2:3),Math.max(.5,10/Math.max(1,T))),w=Math.min(k??(N?10:8),Math.max(2,36/Math.max(1,T)));if(l)return t.jsx(vt,{height:a});if($)return t.jsx(yt,{height:a,text:i});const W=A.reduce((D,Q)=>D+Q.value,0),X=c?Math.min(96,28+Math.ceil(T/3)*22):0,Z=Math.max(140,a-X);return t.jsx("div",{className:`bonsaif-chart bonsaif-${h}-chart w-full ${s}`,role:"img","aria-label":m??(h==="donut"?"Donut chart":"Pie chart"),style:{height:a},children:t.jsxs("div",{className:"bonsaif-pie-layout",children:[t.jsx("div",{className:"bonsaif-pie-plot",style:{height:Z},children:t.jsx(Se.ResponsiveContainer,{width:"100%",height:"100%",children:t.jsxs(Se.PieChart,{margin:{top:4,right:4,bottom:4,left:4},children:[d?t.jsx(Dr,{valueFormat:u,isAnimationActive:!1}):null,t.jsx(Se.Pie,{data:A,dataKey:"value",nameKey:"name",cx:"50%",cy:"50%",innerRadius:`${x}%`,outerRadius:`${y}%`,startAngle:90,endAngle:-270,paddingAngle:L,cornerRadius:w,minAngle:T>6?3:2,stroke:"var(--bg-card)",strokeWidth:2,isAnimationActive:!0,animationDuration:Qt,animationEasing:sr,label:!1,activeShape:rb,children:A.map(D=>t.jsx(Se.Cell,{fill:D.fill},D.name))}),N?t.jsx("text",{x:"50%",y:"50%",textAnchor:"middle",dominantBaseline:"middle",fill:"var(--text-main)",fontSize:18,fontWeight:700,letterSpacing:"-0.02em",children:u(W)}):null]})})}),c?t.jsx("ul",{className:"bonsaif-pie-legend","aria-label":"Leyenda",children:A.map(D=>t.jsxs("li",{className:"bonsaif-pie-legend-item",children:[t.jsx("span",{className:"bonsaif-pie-legend-swatch",style:{background:D.fill},"aria-hidden":!0}),t.jsx("span",{className:"bonsaif-pie-legend-label",title:D.name,children:D.name}),t.jsx("span",{className:"bonsaif-pie-legend-value",children:u(D.value)})]},D.name))}):null]})})}function rb(e){const{outerRadius:r=0,...n}=e;return t.jsx(Se.Sector,{...n,outerRadius:Number(r)+4,stroke:"var(--bg-card)",strokeWidth:2})}function nb({data:e,dataKey:r,width:n="100%",height:a=36,tone:s="primary",color:l,fill:i=!0,className:c="",ariaLabel:d="Sparkline"}){const u=l??Lt(s),m=e.map(y=>Tr(y[r])).filter(y=>y!==null);if(m.length<2)return t.jsx("div",{className:c,style:{width:n,height:a,color:"var(--text-muted)"},"aria-label":d});const b=120,f=36,g=3,v=1,k=Math.min(...m),A=Math.max(...m)-k||1,$=m.map((y,L)=>{const w=v+L/(m.length-1)*(b-v*2),W=f-g-(y-k)/A*(f-g*2);return{x:w,y:W}}),N=$.map((y,L)=>`${L===0?"M":"L"}${y.x.toFixed(2)} ${y.y.toFixed(2)}`).join(" "),T=`${N} L${$[$.length-1].x.toFixed(2)} ${f} L${$[0].x.toFixed(2)} ${f} Z`,x=`bonsaif-spark-${r.replace(/[^a-zA-Z0-9_-]/g,"")}-${s}`;return t.jsx("div",{className:`bonsaif-sparkline ${c}`,style:{width:n,height:a},role:"img","aria-label":d,children:t.jsxs("svg",{width:"100%",height:"100%",viewBox:`0 0 ${b} ${f}`,preserveAspectRatio:"none",focusable:"false",children:[i?t.jsx("defs",{children:t.jsxs("linearGradient",{id:x,x1:"0",y1:"0",x2:"0",y2:"1",children:[t.jsx("stop",{offset:"0%",stopColor:u,stopOpacity:.38}),t.jsx("stop",{offset:"100%",stopColor:u,stopOpacity:0})]})}):null,i?t.jsx("path",{d:T,fill:`url(#${x})`}):null,t.jsx("path",{d:N,fill:"none",stroke:u,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",vectorEffect:"non-scaling-stroke"})]})})}function ab({data:e,xKey:r,series:n,barSeries:a,lineSeries:s,height:l=280,className:i="",loading:c=!1,emptyText:d="Sin datos para mostrar",showGrid:u=!0,showLegend:m=!0,showTooltip:b=!0,margin:f,valueFormat:g=gt,yDomain:v,ariaLabel:k="Gráfico combinado",barRadius:h=6,zoomable:A=!1,zoomMode:$="both",brushHeight:N,onZoomChange:T}){const x=a??n.slice(0,Math.max(1,n.length-1)),y=s??(n.length>1?n.slice(-1):n.length?[n[0]]:[]),L=[...x,...y.filter(j=>!x.some(se=>se.key===j.key))],w=Qn(e,L),W=dn(x),X=dn(L),Z=y.map(j=>{var te;const se=X.find(ee=>ee.key===j.key);return{...j,label:j.label??j.key,color:j.color??(se==null?void 0:se.color)??((te=X[0])==null?void 0:te.color)}}),D=Rn(e,r,{zoomable:A,zoomMode:$,brushHeight:N,onZoomChange:T}),Q=cn({...f,...D.marginExtra});return c?t.jsx(vt,{height:l}):w?t.jsx(yt,{height:l,text:d}):t.jsxs("div",{className:`bonsaif-chart bonsaif-combo-chart w-full ${i}`,role:"img","aria-label":k,style:{height:l},children:[t.jsx(ea,{visible:D.isZoomed,onReset:D.resetZoom}),t.jsx(Se.ResponsiveContainer,{width:"100%",height:"100%",children:t.jsxs(Se.ComposedChart,{data:D.viewData,margin:Q,barCategoryGap:"34%",...D.chartHandlers,children:[u?t.jsx(Se.CartesianGrid,{strokeDasharray:"2 8",stroke:un(),vertical:!1}):null,t.jsx(Se.XAxis,{dataKey:r,tick:xt(),tickLine:!1,axisLine:!1,interval:"preserveStartEnd",minTickGap:36,dy:6}),t.jsx(Se.YAxis,{tick:xt(),tickLine:!1,axisLine:!1,width:44,domain:v??["auto","auto"],tickFormatter:j=>g(Number(j)),dx:-2}),b?t.jsx(Dr,{valueFormat:g,cursor:{fill:"color-mix(in srgb, var(--primary) 8%, transparent)"}}):null,m?t.jsx(Se.Legend,{verticalAlign:"top",align:"right",iconType:"circle",iconSize:7,wrapperStyle:Jn()}):null,W.map(j=>t.jsx(Se.Bar,{dataKey:j.key,name:j.label,fill:j.color,fillOpacity:.88,radius:[h,h,2,2],maxBarSize:18,isAnimationActive:!0,animationDuration:Qt,animationEasing:sr},j.key)),Z.map(j=>t.jsx(Se.Line,{type:"monotone",dataKey:j.key,name:j.label,stroke:j.color,strokeWidth:2.5,isAnimationActive:!0,animationDuration:Qt,animationEasing:sr,dot:!1,activeDot:{r:5,strokeWidth:2,stroke:"var(--bg-card)",fill:j.color}},j.key)),D.zoomNodes]})})]})}function ob({data:e,xKey:r,valueKey:n,typeKey:a,height:s=280,className:l="",loading:i=!1,emptyText:c="Sin datos para mostrar",showGrid:d=!0,showTooltip:u=!0,margin:m,valueFormat:b=gt,ariaLabel:f="Gráfico waterfall",increaseColor:g="#34d399",decreaseColor:v="#f87171",totalColor:k="var(--primary)"}){const h=o.useMemo(()=>sb(e,{xKey:r,valueKey:n,typeKey:a,increaseColor:g,decreaseColor:v,totalColor:k}),[e,r,n,a,g,v,k]),A=!h.length,$=cn(m);return i?t.jsx(vt,{height:s}):A?t.jsx(yt,{height:s,text:c}):t.jsx("div",{className:`bonsaif-chart bonsaif-waterfall-chart w-full ${l}`,role:"img","aria-label":f,style:{height:s},children:t.jsx(Se.ResponsiveContainer,{width:"100%",height:"100%",children:t.jsxs(Se.BarChart,{data:h,margin:$,barCategoryGap:"42%",children:[d?t.jsx(Se.CartesianGrid,{strokeDasharray:"2 8",stroke:un(),vertical:!1}):null,t.jsx(Se.XAxis,{dataKey:"label",tick:xt(),tickLine:!1,axisLine:!1,interval:0,dy:6}),t.jsx(Se.YAxis,{tick:xt(),tickLine:!1,axisLine:!1,width:44,tickFormatter:N=>b(Number(N)),dx:-2}),u?t.jsx(Dr,{valueFormat:b,cursor:{fill:"color-mix(in srgb, var(--primary) 8%, transparent)"}}):null,t.jsx(Se.Bar,{dataKey:"base",stackId:"wf",fill:"transparent",isAnimationActive:!1,legendType:"none",maxBarSize:22}),t.jsx(Se.Bar,{dataKey:"delta",name:"Valor",stackId:"wf",radius:[6,6,2,2],maxBarSize:22,isAnimationActive:!0,animationDuration:Qt,animationEasing:sr,children:h.map(N=>t.jsx(Se.Cell,{fill:N.color},N.label))})]})})})}function sb(e,r){let n=0;return e.map((a,s)=>{const l=Tr(a[r.valueKey])??0,i=r.typeKey?String(a[r.typeKey]??""):"",c=i==="total"||s===e.length-1&&i!=="increase"&&i!=="decrease";let d="increase",u=0,m=0,b=l;return c&&i==="total"?(d="total",u=0,m=Math.abs(l),b=l,n=l):c&&s===e.length-1&&!i?(d="total",u=0,m=Math.abs(n),b=n):(d=i==="decrease"||l<0?"decrease":"increase",d==="decrease"?(u=n+l,m=Math.abs(l),n=n+l):(u=n,m=Math.abs(l),n=n+l),b=l),{label:String(a[r.xKey]??""),base:u,delta:m,display:b,kind:d,color:d==="total"?r.totalColor:d==="decrease"?r.decreaseColor:r.increaseColor}})}const Kl="bonsaif-funnel-chart-keyframes",lb=`
45
45
  @keyframes bonsaif-funnel-stage-in {
46
46
  from {
47
47
  opacity: 0;
@@ -81,4 +81,4 @@ ${ee}`,ne=new Blob(["\uFEFF"+F],{type:"text/csv;charset=utf-8;"}),be=URL.createO
81
81
  animation: none !important;
82
82
  }
83
83
  }
84
- `;function tb(){if(typeof document>"u"||document.getElementById(ql))return;const e=document.createElement("style");e.id=ql,e.textContent=eb,document.head.appendChild(e)}function Ul(e,r,n){return Math.min(n,Math.max(r,e))}function Jn(e,r,n){const a=Ul(n,0,1);return`color-mix(in srgb, ${e} ${Math.round((1-a)*100)}%, ${r} ${Math.round(a*100)}%)`}function rb(e,r,n,a,s,l){const i=e.map((d,u)=>{const m=Tr(d[n])??0,b=String(d[r]??""),f=a?String(d[a]??"").trim():"",g=s?String(d[s]??"").trim():"";return{name:b,value:m,color:l[u%l.length],...f?{title:f}:{},...g?{description:g}:{}}}).filter(d=>d.value>0&&d.name),c=Math.max(...i.map(d=>d.value),1);return i.map(d=>({...d,pct:d.value/c}))}function nb(e,r){const n=e.length;if(n===0)return[];const a=r.gap*Math.max(0,n-1),s=(r.plotH-a)/n,l=r.maxTopW,i=r.maxTopW*r.taper;return e.map((c,d)=>{const u=n===1?0:d/n,m=n===1?1:(d+1)/n,b=l+(i-l)*u,f=l+(i-l)*m;return{...c,index:d,y:r.topY+d*(s+r.gap),h:s,topW:b,bottomW:f,cx:r.cx}})}function ab({stage:e,hovered:r,onHover:n}){const{cx:a,y:s,h:l,topW:i,bottomW:c,color:d}=e,u=a-i/2,m=a+i/2,b=a-c/2,f=a+c/2,g=s+l,v=Math.max(4,Math.min(14,l*.18)),k=Jn(d,"#000",r?.12:.22),h=Jn(d,"#fff",r?.08:0),C=Jn(d,"#fff",.22),M=[`M ${u} ${s}`,`L ${m} ${s}`,`L ${f} ${g}`,`L ${b} ${g}`,"Z"].join(" ");return t.jsxs("g",{onMouseEnter:()=>n(e.index),onMouseLeave:()=>n(null),style:{cursor:"default"},children:[t.jsx("path",{d:M,fill:k}),t.jsx("path",{d:[`M ${u} ${s}`,`L ${m} ${s}`,`L ${m} ${s+1}`,`L ${f} ${g}`,`L ${a} ${g}`,`L ${u} ${s}`,"Z"].join(" "),fill:h,opacity:.55}),t.jsx("ellipse",{cx:a,cy:s,rx:i/2,ry:v,fill:C,stroke:Jn(d,"#000",.15),strokeWidth:1}),r?t.jsx("ellipse",{cx:a,cy:s,rx:i/2,ry:v,fill:"none",stroke:"var(--text-main)",strokeOpacity:.25,strokeWidth:1.5}):null]})}function ob({data:e,nameKey:r,valueKey:n,titleKey:a,descriptionKey:s,height:l=360,className:i="",loading:c=!1,emptyText:d="Sin datos para mostrar",showTooltip:u=!0,showLabels:m=!0,showValues:b=!0,showBottomArrow:f=!0,taper:g=.42,colors:v=[...an],animationDuration:k=Xt,valueFormat:h=wt,ariaLabel:C="Gráfico embudo"}){const[M,y]=o.useState(null),[x,w]=o.useState(!1),N=o.useMemo(()=>rb(e,r,n,a,s,v),[e,r,n,a,s,v]),A=o.useMemo(()=>N.map($=>`${$.name}:${$.value}`).join("|"),[N]);if(o.useEffect(()=>{if(tb(),typeof window>"u")return;const $=window.matchMedia("(prefers-reduced-motion: reduce)");w($.matches);const oe=()=>w($.matches);return $.addEventListener("change",oe),()=>$.removeEventListener("change",oe)},[]),c)return t.jsx(Nt,{height:l});if(!N.length)return t.jsx(kt,{height:l,text:d});const T=k>0&&!x,U=k,K=Math.min(90,Math.max(40,Math.round(k/8))),Z=Math.round(U*.15),L=N.length*K+Math.round(U*.35),Q=N.some($=>$.title||$.description),z=m?160:24,se=Q?168:24,re=f?36:8,R=z+220+se,V=l,B=18,le=Math.max(120,V-B-re-8),j=z+110,ae=nb(N,{cx:j,topY:B,plotH:le,maxTopW:200,taper:Ul(g,.2,.95),gap:10}),H=M!=null?ae[M]:null,D="cubic-bezier(0.22, 1, 0.36, 1)";return t.jsxs("div",{className:`bonsaif-chart bonsaif-funnel-chart relative w-full ${i}`,role:"img","aria-label":C,style:{height:l},children:[t.jsxs("svg",{viewBox:`0 0 ${R} ${V}`,width:"100%",height:"100%",preserveAspectRatio:"xMidYMid meet",children:[m?t.jsx("line",{className:T?"bonsaif-funnel-label":void 0,style:T?{animation:`bonsaif-funnel-fade-in ${U}ms ${D} both`}:void 0,x1:z-12,y1:B,x2:z-12,y2:B+le,stroke:"var(--border)",strokeDasharray:"3 5",strokeWidth:1}):null,ae.map($=>{const oe=$.y+$.h/2,G=$.cx-$.topW/2,X=$.index*K,S=T?{animation:`bonsaif-funnel-stage-in ${U}ms ${D} ${X}ms both`}:void 0,O=T?{animation:`bonsaif-funnel-fade-in ${Math.round(U*.85)}ms ${D} ${X+Z}ms both`}:void 0;return t.jsxs("g",{children:[t.jsx("g",{className:"bonsaif-funnel-stage",style:S,children:t.jsx(ab,{stage:$,hovered:M===$.index,onHover:y})}),m?t.jsxs("g",{className:"bonsaif-funnel-label",style:O,children:[t.jsx("line",{x1:24,y1:oe,x2:z-12,y2:oe,stroke:$.color,strokeOpacity:.55,strokeDasharray:"3 4",strokeWidth:1}),t.jsx("line",{x1:z-12,y1:oe,x2:G-6,y2:oe,stroke:$.color,strokeOpacity:.35,strokeDasharray:"3 4",strokeWidth:1}),t.jsx("text",{x:20,y:oe-(b?6:0),textAnchor:"end",fill:$.color,fontSize:12,fontWeight:600,children:$.name.length>18?`${$.name.slice(0,16)}…`:$.name}),b?t.jsx("text",{x:20,y:oe+10,textAnchor:"end",fill:"var(--text-muted)",fontSize:11,children:h($.value)}):null]}):null,($.title||$.description)&&Q?t.jsxs("g",{className:"bonsaif-funnel-anno",style:O,children:[t.jsx("line",{x1:$.cx+$.bottomW/2+6,y1:oe,x2:z+220+8,y2:oe,stroke:$.color,strokeOpacity:.35,strokeDasharray:"3 4",strokeWidth:1}),$.title?t.jsx("text",{x:z+220+14,y:oe-($.description?6:0),fill:"var(--text-main)",fontSize:12,fontWeight:700,children:$.title.length>22?`${$.title.slice(0,20)}…`:$.title}):null,$.description?t.jsx("text",{x:z+220+14,y:oe+($.title?10:0),fill:"var(--text-muted)",fontSize:11,children:$.description.length>28?`${$.description.slice(0,26)}…`:$.description}):null]}):null]},`${$.name}-${$.index}`)}),f?t.jsx("g",{className:"bonsaif-funnel-arrow",transform:`translate(${j}, ${B+le+8})`,fill:"var(--primary)",style:T?{animation:`bonsaif-funnel-arrow-in ${Math.round(U*.7)}ms ${D} ${L}ms both`}:void 0,children:t.jsx("path",{d:"M0,22 L10,8 L4,8 L4,0 L-4,0 L-4,8 L-10,8 Z"})}):null]},A),u&&H?t.jsxs("div",{className:"pointer-events-none absolute z-10 rounded-md border px-2.5 py-1.5 text-xs shadow-sm",style:{left:"50%",top:8,transform:"translateX(-50%)",background:"var(--bg-card)",borderColor:"var(--border)",color:"var(--text-main)"},children:[t.jsx("span",{className:"font-semibold",style:{color:H.color},children:H.name}),t.jsx("span",{style:{color:"var(--text-muted)"},children:" · "}),h(H.value),t.jsxs("span",{style:{color:"var(--text-muted)"},children:[" ","(",Math.round(H.pct*100),"% del top)"]})]}):null]})}const Ir=135*Math.PI/180,ho=270*Math.PI/180;function sb({value:e,min:r=0,max:n=100,height:a=180,className:s="",loading:l=!1,empty:i=!1,emptyText:c="Sin datos para mostrar",label:d,valueFormat:u=wt,tone:m="primary",color:b,thresholds:f,ariaLabel:g="Gauge",animationDuration:v=700,thickness:k=9,showScale:h=!1}){const C=o.useId().replace(/:/g,""),M=n-r||1,y=Math.min(1,Math.max(0,(e-r)/M)),[x,w]=o.useState(v>0?0:y);if(o.useEffect(()=>{if(l||i)return;if(v<=0){w(y);return}if(typeof window<"u"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches){w(y);return}let R=0,V=0;w(j=>(V=j,j));const B=performance.now(),le=j=>{const W=Math.min(1,(j-B)/v),ae=1-(1-W)**3;w(V+(y-V)*ae),W<1&&(R=requestAnimationFrame(le))};return R=requestAnimationFrame(le),()=>cancelAnimationFrame(R)},[y,v,l,i]),l)return t.jsx(Nt,{height:a});if(i)return t.jsx(kt,{height:a,text:c});const N=100,A=108,T=72,U=b??lb(e,n,m,f),K=r+x*M,Z=Vl(N,A,T,Ir,Ir+ho),L=Ir+Math.max(.001,x)*ho,Q=Vl(N,A,T,Ir,L),z=Rn(N,A,T,Ir),se=Rn(N,A,T,Ir+ho);return t.jsx("div",{className:`bonsaif-chart bonsaif-gauge-chart flex flex-col items-center justify-center ${s}`,style:{height:a},children:t.jsxs("svg",{viewBox:"0 0 200 168",width:"100%",height:"100%",role:"img","aria-label":g,className:"overflow-visible",children:[t.jsx("defs",{children:t.jsxs("linearGradient",{id:`bonsaif-gauge-${C}`,x1:"0",y1:"0",x2:"1",y2:"0",children:[t.jsx("stop",{offset:"0%",stopColor:U,stopOpacity:.82}),t.jsx("stop",{offset:"100%",stopColor:U,stopOpacity:1})]})}),t.jsx("path",{d:Z,fill:"none",stroke:"color-mix(in srgb, var(--border) 70%, transparent)",strokeWidth:k,strokeLinecap:"butt"}),t.jsx("path",{d:Q,fill:"none",stroke:`url(#bonsaif-gauge-${C})`,strokeWidth:k,strokeLinecap:"butt",className:"bonsaif-chart-gauge-value"}),t.jsx("text",{x:N,y:A-(d?4:0),textAnchor:"middle",dominantBaseline:"middle",fill:"var(--text-main)",fontSize:28,fontWeight:700,letterSpacing:"-0.04em",className:"bonsaif-chart-gauge-label",children:u(K)}),d?t.jsx("text",{x:N,y:A+18,textAnchor:"middle",fill:"var(--text-muted)",fontSize:11,fontWeight:600,letterSpacing:"0.06em",children:d}):null,h?t.jsxs(t.Fragment,{children:[t.jsx("text",{x:z.x-2,y:z.y+k+14,textAnchor:"middle",fill:"var(--text-muted)",fontSize:10,children:u(r)}),t.jsx("text",{x:se.x+2,y:se.y+k+14,textAnchor:"middle",fill:"var(--text-muted)",fontSize:10,children:u(n)})]}):null]})})}function lb(e,r,n,a){if(a!=null&&a.length){const l=[...a].sort((c,d)=>c.value-d.value);let i=l[0].color;for(const c of l)e>=c.value&&(i=c.color);return i}if(n)return Dt(n);const s=e/(r||1);return s>=.8?Dt("success"):s>=.5?Dt("warning"):Dt("danger")}function Rn(e,r,n,a){return{x:e+n*Math.cos(a),y:r+n*Math.sin(a)}}function Vl(e,r,n,a,s){const l=Rn(e,r,n,a),i=Rn(e,r,n,s),c=s-a,d=Math.abs(c)>Math.PI?1:0;return`M ${l.x} ${l.y} A ${n} ${n} 0 ${d} 1 ${i.x} ${i.y}`}function ib({value:e,target:r,max:n,ranges:a,height:s=72,className:l="",loading:i=!1,empty:c=!1,emptyText:d="Sin datos para mostrar",label:u,subtitle:m,valueFormat:b=wt,tone:f="primary",showScale:g=!0,showStatus:v=!0,ariaLabel:k="Bullet chart"}){if(i)return t.jsx(Nt,{height:s});if(c)return t.jsx(kt,{height:s,text:d});const h=n??Math.max(e,r,...(a==null?void 0:a.map(U=>U.value))??[],1)*1.05,M=[...a??[{value:h*.5,color:"color-mix(in srgb, var(--border) 72%, transparent)"},{value:h*.75,color:"color-mix(in srgb, var(--border) 48%, transparent)"},{value:h,color:"color-mix(in srgb, var(--border) 28%, transparent)"}]].sort((U,K)=>U.value-K.value),y=Dt(f),x=Math.min(100,Math.max(0,e/h*100)),w=Math.min(100,Math.max(0,r/h*100)),N=e>=r,A=[0,.25,.5,.75,1].map(U=>U*h),T=t.jsxs("div",{className:"bonsaif-bullet-plot min-w-0 flex-1",children:[t.jsxs("div",{className:"bonsaif-bullet-track relative w-full",style:{height:Math.max(22,u?28:s*.42)},role:"img","aria-label":k,children:[t.jsx("div",{className:"bonsaif-bullet-ranges absolute inset-0 flex overflow-hidden",children:M.map((U,K)=>{const Z=K===0?0:M[K-1].value,L=Math.max(0,(U.value-Z)/h*100);return t.jsx("div",{style:{width:`${L}%`,background:U.color??`color-mix(in srgb, var(--border) ${70-K*18}%, transparent)`}},K)})}),t.jsx("div",{className:"absolute left-0 top-1/2 w-full",style:{height:"34%",transform:"translateY(-50%)"},children:t.jsx("div",{className:"bonsaif-bullet-value h-full",style:{width:`${x}%`,background:y,borderRadius:"0 999px 999px 0",boxShadow:`0 0 12px color-mix(in srgb, ${y} 35%, transparent)`}})}),t.jsx("div",{className:"bonsaif-bullet-target absolute top-1/2 z-[1]",style:{left:`${w}%`,height:"72%",width:3,transform:"translate(-50%, -50%)",background:y,borderRadius:1,boxShadow:"0 0 0 1px color-mix(in srgb, var(--bg-card) 70%, transparent)"},title:`Meta ${b(r)}`})]}),g?t.jsx("div",{className:"bonsaif-bullet-scale relative mt-1.5 h-4 w-full",children:A.map((U,K)=>{const Z=U/h*100,L=K===0,Q=K===A.length-1;return t.jsxs("div",{className:"absolute top-0",style:{left:`${Z}%`,transform:L?"none":Q?"translateX(-100%)":"translateX(-50%)"},children:[t.jsx("div",{className:"mx-auto h-1.5 w-px",style:{background:"color-mix(in srgb, var(--text-muted) 55%, transparent)",marginLeft:L?0:Q?"auto":void 0,marginRight:Q?0:void 0}}),t.jsx("div",{className:"bonsaif-bullet-scale-label mt-0.5 tabular-nums",style:{color:"var(--text-muted)",textAlign:L?"left":Q?"right":"center"},children:b(U)})]},U)})}):null]});return t.jsx("div",{className:`bonsaif-chart bonsaif-bullet-chart w-full ${l}`,children:u?t.jsxs("div",{className:"bonsaif-bullet-row flex flex-col gap-2 sm:flex-row sm:items-start sm:gap-4",children:[t.jsxs("div",{className:"bonsaif-bullet-label shrink-0 sm:w-[7.5rem] sm:pt-1 sm:text-right",children:[t.jsx("div",{className:"text-sm font-semibold tracking-tight",style:{color:"var(--text-main)"},children:u}),m?t.jsx("div",{className:"mt-0.5 text-[11px] leading-snug",style:{color:"var(--text-muted)"},children:m}):t.jsxs("div",{className:"mt-0.5 text-[11px] tabular-nums leading-snug",style:{color:"var(--text-muted)"},children:[t.jsx("span",{style:{color:y,fontWeight:600},children:b(e)}),t.jsxs("span",{children:[" / meta ",b(r)]})]}),v?t.jsx("div",{className:"bonsaif-bullet-status mt-1.5 inline-flex text-[10px] font-bold uppercase tracking-wide",style:{color:Dt(N?"success":"warning")},children:N?"En meta":"Bajo meta"}):null]}),T]}):T})}function cb({data:e,value:r,timeKey:n="t",usageKey:a="usage",series:s,cores:l,height:i=220,className:c="",loading:d=!1,emptyText:u="Sin datos de CPU",showLegend:m=!1,showTooltip:b=!0,thresholds:f,label:g="CPU",ariaLabel:v="Uso de CPU"}){var w;const k=s??[{key:a,label:"Uso",color:on(r??Lr(e,a)??0,f)}],h=r??Lr(e,a)??Lr(e,((w=k[0])==null?void 0:w.key)??a),C=!d&&(!e.length||h===null);if(d)return t.jsx(Nt,{height:i});if(C)return t.jsx(kt,{height:i,text:u});const M=Math.min(100,Math.max(0,h??0)),y=Yn(M,f),x=on(M,f);return t.jsxs("div",{className:`bonsaif-chart bonsaif-cpu-chart w-full ${c}`,role:"group","aria-label":v,children:[t.jsxs("div",{className:"bonsaif-metric-head",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"bonsaif-metric-kicker",children:[g,l!=null?t.jsxs("span",{className:"ml-1.5 normal-case tracking-normal opacity-80",children:["· ",l," ",l===1?"core":"cores"]}):null]}),t.jsx("div",{className:"bonsaif-metric-value",style:{color:x},children:$r(M,M<10?1:0)})]}),t.jsx("div",{className:"bonsaif-metric-badge",style:{color:x,background:`color-mix(in srgb, ${x} 14%, transparent)`},children:y==="danger"?"Crítico":y==="warning"?"Alto":"Normal"})]}),t.jsx(Qn,{data:e,xKey:n,series:k.map(N=>({...N,color:N.color??x})),height:Math.max(120,i-56),yDomain:[0,100],showLegend:m,showTooltip:b,valueFormat:N=>$r(N,0),ariaLabel:v,opacity:.22,margin:{top:8,right:8,bottom:4,left:0}})]})}function db({used:e,total:r,cached:n,data:a=[],timeKey:s="t",usageKey:l="usage",height:i=220,className:c="",loading:d=!1,emptyText:u="Sin datos de memoria",showHistory:m=!0,showTooltip:b=!0,thresholds:f,label:g="RAM",ariaLabel:v="Uso de memoria"}){const k=r>0?r:1,h=Math.min(100,Math.max(0,e/k*100)),C=!d&&!(Number.isFinite(e)&&Number.isFinite(r)&&r>0);if(d)return t.jsx(Nt,{height:i});if(C)return t.jsx(kt,{height:i,text:u});const M=Yn(h,f),y=on(h,f),x=Math.max(0,r-e),w=a.length>0?Lr(a,l)??h:h,N=on(w,f),A=m&&a.length>1?Math.max(100,i-110):0;return t.jsxs("div",{className:`bonsaif-chart bonsaif-ram-chart w-full ${c}`,role:"group","aria-label":v,children:[t.jsxs("div",{className:"bonsaif-metric-head",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"bonsaif-metric-kicker",children:g}),t.jsxs("div",{className:"flex items-baseline gap-2",children:[t.jsx("span",{className:"bonsaif-metric-value",style:{color:y},children:$r(h,h<10?1:0)}),t.jsxs("span",{className:"text-sm tabular-nums",style:{color:"var(--text-secondary)"},children:[Ar(e)," / ",Ar(r)]})]})]}),t.jsx("div",{className:"bonsaif-metric-badge",style:{color:y,background:`color-mix(in srgb, ${y} 14%, transparent)`},children:M==="danger"?"Crítico":M==="warning"?"Alto":"Normal"})]}),t.jsxs("div",{className:"mb-2",children:[t.jsx("div",{className:"h-2 w-full overflow-hidden rounded-sm",style:{background:"color-mix(in srgb, var(--border) 55%, transparent)"},role:"progressbar","aria-valuenow":Math.round(h),"aria-valuemin":0,"aria-valuemax":100,"aria-label":`${g} ${$r(h,0)}`,children:t.jsx("div",{className:"h-full rounded-sm transition-[width] duration-300",style:{width:`${h}%`,background:`linear-gradient(90deg, ${y}, color-mix(in srgb, ${y} 55%, #38bdf8))`}})}),t.jsxs("div",{className:"mt-2 flex flex-wrap gap-x-4 gap-y-1 text-[11px] tabular-nums",style:{color:"var(--text-muted)"},children:[t.jsxs("span",{children:[t.jsx("span",{className:"font-medium",style:{color:"var(--text-main)"},children:"Usada"})," ",Ar(e)]}),n!=null&&Number.isFinite(n)?t.jsxs("span",{children:[t.jsx("span",{className:"font-medium",style:{color:"var(--text-main)"},children:"Caché"})," ",Ar(n)]}):null,t.jsxs("span",{children:[t.jsx("span",{className:"font-medium",style:{color:"var(--text-main)"},children:"Libre"})," ",Ar(x)]})]})]}),m&&a.length>1?t.jsx(Qn,{data:a,xKey:s,series:[{key:l,label:"Uso",color:N}],height:A,yDomain:[0,100],showLegend:!1,showTooltip:b,valueFormat:T=>$r(T,0),ariaLabel:`${v} — historial`,opacity:.22,margin:{top:8,right:8,bottom:4,left:0}}):null]})}const ub="color-mix(in srgb, var(--primary) 25%, #38bdf8)",fb="color-mix(in srgb, var(--primary) 20%, #2dd4bf)";function bb({data:e,timeKey:r="t",inboundKey:n="in",outboundKey:a="out",inbound:s,outbound:l,unit:i="bytes",inboundLabel:c="Entrada",outboundLabel:d="Salida",inboundColor:u=ub,outboundColor:m=fb,height:b=240,className:f="",loading:g=!1,emptyText:v="Sin datos de red",showLegend:k=!1,showTooltip:h=!0,label:C="Network",ariaLabel:M="Tráfico de red"}){const y=s??Lr(e,n)??0,x=l??Lr(e,a)??0,w=!g&&e.length===0;if(g)return t.jsx(Nt,{height:b});if(w)return t.jsx(kt,{height:b,text:v});const N=U=>Bl(U,i),T=Math.max(140,b-76);return t.jsxs("div",{className:`bonsaif-chart bonsaif-network-chart w-full ${f}`,role:"group","aria-label":M,children:[t.jsx("div",{className:"bonsaif-network-header relative z-10 mb-4 grid gap-3 border-b pb-3 sm:grid-cols-[minmax(0,1.4fr)_minmax(0,1fr)]",style:{borderColor:"var(--border)"},children:t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"bonsaif-metric-kicker",children:C}),t.jsxs("div",{className:"mt-2 grid grid-cols-2 gap-5 sm:max-w-lg",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",style:{color:"var(--text-muted)"},children:[t.jsx("span",{className:"h-3 w-1.5 shrink-0 rounded-sm",style:{background:u},"aria-hidden":!0}),c]}),t.jsx("div",{className:"mt-1 truncate text-xl font-bold tabular-nums leading-tight tracking-tight",style:{color:u},title:N(y),children:N(y)})]}),t.jsxs("div",{className:"min-w-0 pl-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",style:{color:"var(--text-muted)"},children:[t.jsx("span",{className:"h-3 w-1.5 shrink-0 rounded-sm",style:{background:m},"aria-hidden":!0}),d]}),t.jsx("div",{className:"mt-1 truncate text-lg font-semibold tabular-nums leading-tight tracking-tight opacity-95",style:{color:m},title:N(x),children:N(x)})]})]})]})}),t.jsx("div",{className:"bonsaif-network-plot relative z-0",children:t.jsx(Qn,{data:e,xKey:r,series:[{key:n,label:c,color:u},{key:a,label:d,color:m}],height:T,showLegend:k,showTooltip:h,valueFormat:N,ariaLabel:M,opacity:.18,margin:{top:8,right:8,bottom:4,left:4}})})]})}const Yl=["primeSuiteOrigin","primeAuthOrigin","primeSuiteAppUrl"],Xl=["primeSuiteOrigin","primeSuiteProjectKey"];function mb(){if(typeof window>"u")return"*";try{if(window.parent===window)return"*";const e=new URLSearchParams(window.location.search);for(const r of Yl){const n=e.get(r);if(n){const a=ea(n);if(a)return a}}if(typeof sessionStorage<"u")for(const r of Xl){const n=sessionStorage.getItem(r);if(n)try{const a=new URL(n);if(a.origin&&a.origin!==window.location.origin)return a.origin}catch{const a=ea(n);if(a)return a}}if(document.referrer){const r=ea(document.referrer);if(r&&r!==window.location.origin)return r}return"*"}catch{return"*"}}function pb(){if(typeof window>"u")return"self";try{if(window.parent===window)return"self";const e=new URLSearchParams(window.location.search);for(const r of Yl)if(e.get(r))return"query";if(typeof sessionStorage<"u"){for(const r of Xl)if(sessionStorage.getItem(r))return"sessionStorage"}if(document.referrer){const r=ea(document.referrer);if(r&&r!==window.location.origin)return"referrer"}return"wildcard"}catch{return"wildcard"}}function ea(e){if(!e)return null;const r=e.trim().replace(/\/+$/,"");if(!r)return null;if(/^https?:\/\/[^/]+$/.test(r))return r;try{return new URL(r).origin}catch{return null}}function hb(e){const[r,n]=o.useState({}),[a,s]=o.useState(!1),l=o.useCallback(u=>a||r[u]?e[u]:void 0,[e,a,r]),i=o.useCallback(u=>{n(m=>({...m,[u]:!0}))},[]),c=o.useCallback(()=>{s(!0)},[]),d=o.useCallback(()=>{n({}),s(!1)},[]);return{submitted:a,touchedFields:r,getFieldError:l,touchField:i,submit:c,reset:d}}Object.defineProperty(Y,"toast",{enumerable:!0,get:()=>Ho.toast}),Y.Alert=Vi,Y.AreaChart=Qn,Y.AuthShell=Al,Y.AutoGrowTextarea=fl,Y.AutoGrowTextareaField=ju,Y.BarChart=Yf,Y.BonsaifButton=Ei,Y.BonsaifUIToaster=zf,Y.BulletChart=ib,Y.Button=Ue,Y.CHART_PALETTE=an,Y.CalendarPicker=Zi,Y.ChartCard=Wf,Y.Checkbox=vn,Y.CodeBlock=tc,Y.ComboChart=Qf,Y.CompactFilterSelect=ac,Y.CompactSearchInput=nc,Y.ConfirmDialog=ic,Y.CopyButton=Ma,Y.CopyLinkButton=fc,Y.CpuChart=cb,Y.DataSheets=Pc,Y.DataTable=ns,Y.DateRangePicker=qc,Y.DonutChart=Kf,Y.Drawer=Jc,Y.DropdownMenu=Zc,Y.DynamicDetailTabs=qi,Y.EmailField=wd,Y.EmptyState=kd,Y.FieldHelperFooter=wr,Y.FieldLabelInfo=xr,Y.FieldLayoutEditor=$d,Y.FileUpload=Md,Y.FormField=$n,Y.FunnelChart=ob,Y.GaugeChart=sb,Y.GlobalScrollbars=Sl,Y.ImageLightbox=ks,Y.ImageLightboxHost=Pd,Y.InputField=ja,Y.LineChart=Vf,Y.LoadingState=jo,Y.MentionTextEditor=cl,Y.MicroserviceFrame=Hf,Y.Modal=Aa,Y.MouseTooltip=nr,Y.MultiDateCalendar=Vc,Y.MultiSelect=zd,Y.NetworkChart=bb,Y.NumberField=Wd,Y.PageHeader=Df,Y.PageSearchInput=Fo,Y.Pagination=qd,Y.PhoneField=Vd,Y.PieChart=Xf,Y.PrimeAuthRouteShell=If,Y.PrimeSuiteChatFrame=Bf,Y.RadioGroup=Yd,Y.RamChart=db,Y.RichTextEditor=Mu,Y.SearchableSelect=ar,Y.SectionPanel=Tu,Y.Sparkline=Zf,Y.StatusBadge=Lu,Y.StatusSelect=Bu,Y.StepWizard=Pu,Y.TableSkeleton=gn,Y.Tabs=Fu,Y.TagInput=Ju,Y.TextInput=Tn,Y.Textarea=bl,Y.TextareaField=Xu,Y.TimeField=sf,Y.TimePicker=xl,Y.Toggle=cf,Y.UserAvatar=$l,Y.WaterfallChart=Jf,Y.YearMultiDateCalendar=Xc,Y.buildMentionQueryRegex=qs,Y.clearMentionChipSelection=Er,Y.cn=jt,Y.configureBonsaifUI=pc,Y.dedupeMentions=Ks,Y.defaultValueFormat=wt,Y.deleteEditorSelection=nl,Y.describeParentTargetOrigin=pb,Y.emailFormat=ad,Y.extractMentionUsernames=ro,Y.filterSelfMentions=xu,Y.findMentionChipAfterCaret=ol,Y.findMentionChipBeforeCaret=al,Y.findMentionChipsInSelection=oo,Y.findMentionTriggerInEditor=eo,Y.formatBytes=Ar,Y.formatPercent=$r,Y.formatRate=Bl,Y.getBonsaifUIConfig=hc,Y.getDataTablePreferencesEndpoint=La,Y.getEditorPlainText=ao,Y.getPlainTextOffset=_n,Y.highlightMentions=Gs,Y.htmlToText=Ys,Y.insertMentionInEditor=Qs,Y.isMentionTriggerBoundary=Vs,Y.isPlainOffsetInsideMentionChip=Us,Y.isValidEmail=_a,Y.isValidPhone=za,Y.locateTextOffset=Cr,Y.matches=dd,Y.maxLength=ld,Y.maxValue=cd,Y.mentionDisplayLabel=Xs,Y.minLength=sd,Y.minValue=id,Y.normalizeUsername=to,Y.openImageLightboxFromEvent=ws,Y.phoneCountryCodeOptions=Es,Y.phoneFormat=od,Y.placeCaretAtTextOffset=Js,Y.removeMentionChip=jn,Y.required=nd,Y.resetBonsaifUIConfig=gc,Y.resolveMentions=yu,Y.resolveParentTargetOrigin=mb,Y.selectAllEditorContents=tl,Y.selectMentionChip=el,Y.selectionIncludesNonChipText=rl,Y.seriesColor=Hl,Y.setBonsaifDataTablePreferencesEndpoint=vc,Y.syncMentionChipSelectionHighlight=Wn,Y.toneColor=Dt,Y.usageColor=on,Y.usageTone=Yn,Y.useValidationVisibility=hb,Y.validateForm=ud,Object.defineProperty(Y,Symbol.toStringTag,{value:"Module"})}));
84
+ `;function ib(){if(typeof document>"u"||document.getElementById(Kl))return;const e=document.createElement("style");e.id=Kl,e.textContent=lb,document.head.appendChild(e)}function Gl(e,r,n){return Math.min(n,Math.max(r,e))}function ra(e,r,n){const a=Gl(n,0,1);return`color-mix(in srgb, ${e} ${Math.round((1-a)*100)}%, ${r} ${Math.round(a*100)}%)`}function cb(e,r,n,a,s,l){const i=e.map((d,u)=>{const m=Tr(d[n])??0,b=String(d[r]??""),f=a?String(d[a]??"").trim():"",g=s?String(d[s]??"").trim():"";return{name:b,value:m,color:l[u%l.length],...f?{title:f}:{},...g?{description:g}:{}}}).filter(d=>d.value>0&&d.name),c=Math.max(...i.map(d=>d.value),1);return i.map(d=>({...d,pct:d.value/c}))}function db(e,r){const n=e.length;if(n===0)return[];const a=r.gap*Math.max(0,n-1),s=(r.plotH-a)/n,l=r.maxTopW,i=r.maxTopW*r.taper;return e.map((c,d)=>{const u=n===1?0:d/n,m=n===1?1:(d+1)/n,b=l+(i-l)*u,f=l+(i-l)*m;return{...c,index:d,y:r.topY+d*(s+r.gap),h:s,topW:b,bottomW:f,cx:r.cx}})}function ub({stage:e,hovered:r,onHover:n}){const{cx:a,y:s,h:l,topW:i,bottomW:c,color:d}=e,u=a-i/2,m=a+i/2,b=a-c/2,f=a+c/2,g=s+l,v=Math.max(4,Math.min(14,l*.18)),k=ra(d,"#000",r?.12:.22),h=ra(d,"#fff",r?.08:0),A=ra(d,"#fff",.22),$=[`M ${u} ${s}`,`L ${m} ${s}`,`L ${f} ${g}`,`L ${b} ${g}`,"Z"].join(" ");return t.jsxs("g",{onMouseEnter:()=>n(e.index),onMouseLeave:()=>n(null),style:{cursor:"default"},children:[t.jsx("path",{d:$,fill:k}),t.jsx("path",{d:[`M ${u} ${s}`,`L ${m} ${s}`,`L ${m} ${s+1}`,`L ${f} ${g}`,`L ${a} ${g}`,`L ${u} ${s}`,"Z"].join(" "),fill:h,opacity:.55}),t.jsx("ellipse",{cx:a,cy:s,rx:i/2,ry:v,fill:A,stroke:ra(d,"#000",.15),strokeWidth:1}),r?t.jsx("ellipse",{cx:a,cy:s,rx:i/2,ry:v,fill:"none",stroke:"var(--text-main)",strokeOpacity:.25,strokeWidth:1.5}):null]})}function fb({data:e,nameKey:r,valueKey:n,titleKey:a,descriptionKey:s,height:l=360,className:i="",loading:c=!1,emptyText:d="Sin datos para mostrar",showTooltip:u=!0,showLabels:m=!0,showValues:b=!0,showBottomArrow:f=!0,taper:g=.42,colors:v=[...sn],animationDuration:k=Qt,valueFormat:h=gt,ariaLabel:A="Gráfico embudo"}){const[$,N]=o.useState(null),[T,x]=o.useState(!1),y=o.useMemo(()=>cb(e,r,n,a,s,v),[e,r,n,a,s,v]),L=o.useMemo(()=>y.map(E=>`${E.name}:${E.value}`).join("|"),[y]);if(o.useEffect(()=>{if(ib(),typeof window>"u")return;const E=window.matchMedia("(prefers-reduced-motion: reduce)");x(E.matches);const oe=()=>x(E.matches);return E.addEventListener("change",oe),()=>E.removeEventListener("change",oe)},[]),c)return t.jsx(vt,{height:l});if(!y.length)return t.jsx(yt,{height:l,text:d});const w=k>0&&!T,W=k,X=Math.min(90,Math.max(40,Math.round(k/8))),Z=Math.round(W*.15),D=y.length*X+Math.round(W*.35),Q=y.some(E=>E.title||E.description),j=m?160:24,se=Q?168:24,te=f?36:8,ee=j+220+se,U=l,J=18,ce=Math.max(120,U-J-te-8),C=j+110,ae=db(y,{cx:C,topY:J,plotH:ce,maxTopW:200,taper:Gl(g,.2,.95),gap:10}),B=$!=null?ae[$]:null,I="cubic-bezier(0.22, 1, 0.36, 1)";return t.jsxs("div",{className:`bonsaif-chart bonsaif-funnel-chart relative w-full ${i}`,role:"img","aria-label":A,style:{height:l},children:[t.jsxs("svg",{viewBox:`0 0 ${ee} ${U}`,width:"100%",height:"100%",preserveAspectRatio:"xMidYMid meet",children:[m?t.jsx("line",{className:w?"bonsaif-funnel-label":void 0,style:w?{animation:`bonsaif-funnel-fade-in ${W}ms ${I} both`}:void 0,x1:j-12,y1:J,x2:j-12,y2:J+ce,stroke:"var(--border)",strokeDasharray:"3 5",strokeWidth:1}):null,ae.map(E=>{const oe=E.y+E.h/2,K=E.cx-E.topW/2,Y=E.index*X,S=w?{animation:`bonsaif-funnel-stage-in ${W}ms ${I} ${Y}ms both`}:void 0,H=w?{animation:`bonsaif-funnel-fade-in ${Math.round(W*.85)}ms ${I} ${Y+Z}ms both`}:void 0;return t.jsxs("g",{children:[t.jsx("g",{className:"bonsaif-funnel-stage",style:S,children:t.jsx(ub,{stage:E,hovered:$===E.index,onHover:N})}),m?t.jsxs("g",{className:"bonsaif-funnel-label",style:H,children:[t.jsx("line",{x1:24,y1:oe,x2:j-12,y2:oe,stroke:E.color,strokeOpacity:.55,strokeDasharray:"3 4",strokeWidth:1}),t.jsx("line",{x1:j-12,y1:oe,x2:K-6,y2:oe,stroke:E.color,strokeOpacity:.35,strokeDasharray:"3 4",strokeWidth:1}),t.jsx("text",{x:20,y:oe-(b?6:0),textAnchor:"end",fill:E.color,fontSize:12,fontWeight:600,children:E.name.length>18?`${E.name.slice(0,16)}…`:E.name}),b?t.jsx("text",{x:20,y:oe+10,textAnchor:"end",fill:"var(--text-muted)",fontSize:11,children:h(E.value)}):null]}):null,(E.title||E.description)&&Q?t.jsxs("g",{className:"bonsaif-funnel-anno",style:H,children:[t.jsx("line",{x1:E.cx+E.bottomW/2+6,y1:oe,x2:j+220+8,y2:oe,stroke:E.color,strokeOpacity:.35,strokeDasharray:"3 4",strokeWidth:1}),E.title?t.jsx("text",{x:j+220+14,y:oe-(E.description?6:0),fill:"var(--text-main)",fontSize:12,fontWeight:700,children:E.title.length>22?`${E.title.slice(0,20)}…`:E.title}):null,E.description?t.jsx("text",{x:j+220+14,y:oe+(E.title?10:0),fill:"var(--text-muted)",fontSize:11,children:E.description.length>28?`${E.description.slice(0,26)}…`:E.description}):null]}):null]},`${E.name}-${E.index}`)}),f?t.jsx("g",{className:"bonsaif-funnel-arrow",transform:`translate(${C}, ${J+ce+8})`,fill:"var(--primary)",style:w?{animation:`bonsaif-funnel-arrow-in ${Math.round(W*.7)}ms ${I} ${D}ms both`}:void 0,children:t.jsx("path",{d:"M0,22 L10,8 L4,8 L4,0 L-4,0 L-4,8 L-10,8 Z"})}):null]},L),u&&B?t.jsxs("div",{className:"pointer-events-none absolute z-10 rounded-md border px-2.5 py-1.5 text-xs shadow-sm",style:{left:"50%",top:8,transform:"translateX(-50%)",background:"var(--bg-card)",borderColor:"var(--border)",color:"var(--text-main)"},children:[t.jsx("span",{className:"font-semibold",style:{color:B.color},children:B.name}),t.jsx("span",{style:{color:"var(--text-muted)"},children:" · "}),h(B.value),t.jsxs("span",{style:{color:"var(--text-muted)"},children:[" ","(",Math.round(B.pct*100),"% del top)"]})]}):null]})}const Ir=135*Math.PI/180,wo=270*Math.PI/180;function bb({value:e,min:r=0,max:n=100,height:a=180,className:s="",loading:l=!1,empty:i=!1,emptyText:c="Sin datos para mostrar",label:d,valueFormat:u=gt,tone:m="primary",color:b,thresholds:f,ariaLabel:g="Gauge",animationDuration:v=700,thickness:k=9,showScale:h=!1}){const A=o.useId().replace(/:/g,""),$=n-r||1,N=Math.min(1,Math.max(0,(e-r)/$)),[T,x]=o.useState(v>0?0:N);if(o.useEffect(()=>{if(l||i)return;if(v<=0){x(N);return}if(typeof window<"u"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches){x(N);return}let ee=0,U=0;x(C=>(U=C,C));const J=performance.now(),ce=C=>{const _=Math.min(1,(C-J)/v),ae=1-(1-_)**3;x(U+(N-U)*ae),_<1&&(ee=requestAnimationFrame(ce))};return ee=requestAnimationFrame(ce),()=>cancelAnimationFrame(ee)},[N,v,l,i]),l)return t.jsx(vt,{height:a});if(i)return t.jsx(yt,{height:a,text:c});const y=100,L=108,w=72,W=b??mb(e,n,m,f),X=r+T*$,Z=Zl(y,L,w,Ir,Ir+wo),D=Ir+Math.max(.001,T)*wo,Q=Zl(y,L,w,Ir,D),j=na(y,L,w,Ir),se=na(y,L,w,Ir+wo);return t.jsx("div",{className:`bonsaif-chart bonsaif-gauge-chart flex flex-col items-center justify-center ${s}`,style:{height:a},children:t.jsxs("svg",{viewBox:"0 0 200 168",width:"100%",height:"100%",role:"img","aria-label":g,className:"overflow-visible",children:[t.jsx("defs",{children:t.jsxs("linearGradient",{id:`bonsaif-gauge-${A}`,x1:"0",y1:"0",x2:"1",y2:"0",children:[t.jsx("stop",{offset:"0%",stopColor:W,stopOpacity:.82}),t.jsx("stop",{offset:"100%",stopColor:W,stopOpacity:1})]})}),t.jsx("path",{d:Z,fill:"none",stroke:"color-mix(in srgb, var(--border) 70%, transparent)",strokeWidth:k,strokeLinecap:"butt"}),t.jsx("path",{d:Q,fill:"none",stroke:`url(#bonsaif-gauge-${A})`,strokeWidth:k,strokeLinecap:"butt",className:"bonsaif-chart-gauge-value"}),t.jsx("text",{x:y,y:L-(d?4:0),textAnchor:"middle",dominantBaseline:"middle",fill:"var(--text-main)",fontSize:28,fontWeight:700,letterSpacing:"-0.04em",className:"bonsaif-chart-gauge-label",children:u(X)}),d?t.jsx("text",{x:y,y:L+18,textAnchor:"middle",fill:"var(--text-muted)",fontSize:11,fontWeight:600,letterSpacing:"0.06em",children:d}):null,h?t.jsxs(t.Fragment,{children:[t.jsx("text",{x:j.x-2,y:j.y+k+14,textAnchor:"middle",fill:"var(--text-muted)",fontSize:10,children:u(r)}),t.jsx("text",{x:se.x+2,y:se.y+k+14,textAnchor:"middle",fill:"var(--text-muted)",fontSize:10,children:u(n)})]}):null]})})}function mb(e,r,n,a){if(a!=null&&a.length){const l=[...a].sort((c,d)=>c.value-d.value);let i=l[0].color;for(const c of l)e>=c.value&&(i=c.color);return i}if(n)return Lt(n);const s=e/(r||1);return s>=.8?Lt("success"):s>=.5?Lt("warning"):Lt("danger")}function na(e,r,n,a){return{x:e+n*Math.cos(a),y:r+n*Math.sin(a)}}function Zl(e,r,n,a,s){const l=na(e,r,n,a),i=na(e,r,n,s),c=s-a,d=Math.abs(c)>Math.PI?1:0;return`M ${l.x} ${l.y} A ${n} ${n} 0 ${d} 1 ${i.x} ${i.y}`}function pb({value:e,target:r,max:n,ranges:a,height:s=72,className:l="",loading:i=!1,empty:c=!1,emptyText:d="Sin datos para mostrar",label:u,subtitle:m,valueFormat:b=gt,tone:f="primary",showScale:g=!0,showStatus:v=!0,ariaLabel:k="Bullet chart"}){if(i)return t.jsx(vt,{height:s});if(c)return t.jsx(yt,{height:s,text:d});const h=n??Math.max(e,r,...(a==null?void 0:a.map(W=>W.value))??[],1)*1.05,$=[...a??[{value:h*.5,color:"color-mix(in srgb, var(--border) 72%, transparent)"},{value:h*.75,color:"color-mix(in srgb, var(--border) 48%, transparent)"},{value:h,color:"color-mix(in srgb, var(--border) 28%, transparent)"}]].sort((W,X)=>W.value-X.value),N=Lt(f),T=Math.min(100,Math.max(0,e/h*100)),x=Math.min(100,Math.max(0,r/h*100)),y=e>=r,L=[0,.25,.5,.75,1].map(W=>W*h),w=t.jsxs("div",{className:"bonsaif-bullet-plot min-w-0 flex-1",children:[t.jsxs("div",{className:"bonsaif-bullet-track relative w-full",style:{height:Math.max(22,u?28:s*.42)},role:"img","aria-label":k,children:[t.jsx("div",{className:"bonsaif-bullet-ranges absolute inset-0 flex overflow-hidden",children:$.map((W,X)=>{const Z=X===0?0:$[X-1].value,D=Math.max(0,(W.value-Z)/h*100);return t.jsx("div",{style:{width:`${D}%`,background:W.color??`color-mix(in srgb, var(--border) ${70-X*18}%, transparent)`}},X)})}),t.jsx("div",{className:"absolute left-0 top-1/2 w-full",style:{height:"34%",transform:"translateY(-50%)"},children:t.jsx("div",{className:"bonsaif-bullet-value h-full",style:{width:`${T}%`,background:N,borderRadius:"0 999px 999px 0",boxShadow:`0 0 12px color-mix(in srgb, ${N} 35%, transparent)`}})}),t.jsx("div",{className:"bonsaif-bullet-target absolute top-1/2 z-[1]",style:{left:`${x}%`,height:"72%",width:3,transform:"translate(-50%, -50%)",background:N,borderRadius:1,boxShadow:"0 0 0 1px color-mix(in srgb, var(--bg-card) 70%, transparent)"},title:`Meta ${b(r)}`})]}),g?t.jsx("div",{className:"bonsaif-bullet-scale relative mt-1.5 h-4 w-full",children:L.map((W,X)=>{const Z=W/h*100,D=X===0,Q=X===L.length-1;return t.jsxs("div",{className:"absolute top-0",style:{left:`${Z}%`,transform:D?"none":Q?"translateX(-100%)":"translateX(-50%)"},children:[t.jsx("div",{className:"mx-auto h-1.5 w-px",style:{background:"color-mix(in srgb, var(--text-muted) 55%, transparent)",marginLeft:D?0:Q?"auto":void 0,marginRight:Q?0:void 0}}),t.jsx("div",{className:"bonsaif-bullet-scale-label mt-0.5 tabular-nums",style:{color:"var(--text-muted)",textAlign:D?"left":Q?"right":"center"},children:b(W)})]},W)})}):null]});return t.jsx("div",{className:`bonsaif-chart bonsaif-bullet-chart w-full ${l}`,children:u?t.jsxs("div",{className:"bonsaif-bullet-row flex flex-col gap-2 sm:flex-row sm:items-start sm:gap-4",children:[t.jsxs("div",{className:"bonsaif-bullet-label shrink-0 sm:w-[7.5rem] sm:pt-1 sm:text-right",children:[t.jsx("div",{className:"text-sm font-semibold tracking-tight",style:{color:"var(--text-main)"},children:u}),m?t.jsx("div",{className:"mt-0.5 text-[11px] leading-snug",style:{color:"var(--text-muted)"},children:m}):t.jsxs("div",{className:"mt-0.5 text-[11px] tabular-nums leading-snug",style:{color:"var(--text-muted)"},children:[t.jsx("span",{style:{color:N,fontWeight:600},children:b(e)}),t.jsxs("span",{children:[" / meta ",b(r)]})]}),v?t.jsx("div",{className:"bonsaif-bullet-status mt-1.5 inline-flex text-[10px] font-bold uppercase tracking-wide",style:{color:Lt(y?"success":"warning")},children:y?"En meta":"Bajo meta"}):null]}),w]}):w})}function hb({data:e,value:r,timeKey:n="t",usageKey:a="usage",series:s,cores:l,height:i=220,className:c="",loading:d=!1,emptyText:u="Sin datos de CPU",showLegend:m=!1,showTooltip:b=!0,thresholds:f,label:g="CPU",ariaLabel:v="Uso de CPU"}){var x;const k=s??[{key:a,label:"Uso",color:ln(r??Lr(e,a)??0,f)}],h=r??Lr(e,a)??Lr(e,((x=k[0])==null?void 0:x.key)??a),A=!d&&(!e.length||h===null);if(d)return t.jsx(vt,{height:i});if(A)return t.jsx(yt,{height:i,text:u});const $=Math.min(100,Math.max(0,h??0)),N=Zn($,f),T=ln($,f);return t.jsxs("div",{className:`bonsaif-chart bonsaif-cpu-chart w-full ${c}`,role:"group","aria-label":v,children:[t.jsxs("div",{className:"bonsaif-metric-head",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"bonsaif-metric-kicker",children:[g,l!=null?t.jsxs("span",{className:"ml-1.5 normal-case tracking-normal opacity-80",children:["· ",l," ",l===1?"core":"cores"]}):null]}),t.jsx("div",{className:"bonsaif-metric-value",style:{color:T},children:$r($,$<10?1:0)})]}),t.jsx("div",{className:"bonsaif-metric-badge",style:{color:T,background:`color-mix(in srgb, ${T} 14%, transparent)`},children:N==="danger"?"Crítico":N==="warning"?"Alto":"Normal"})]}),t.jsx(ta,{data:e,xKey:n,series:k.map(y=>({...y,color:y.color??T})),height:Math.max(120,i-56),yDomain:[0,100],showLegend:m,showTooltip:b,valueFormat:y=>$r(y,0),ariaLabel:v,opacity:.22,margin:{top:8,right:8,bottom:4,left:0}})]})}function gb({used:e,total:r,cached:n,data:a=[],timeKey:s="t",usageKey:l="usage",height:i=220,className:c="",loading:d=!1,emptyText:u="Sin datos de memoria",showHistory:m=!0,showTooltip:b=!0,thresholds:f,label:g="RAM",ariaLabel:v="Uso de memoria"}){const k=r>0?r:1,h=Math.min(100,Math.max(0,e/k*100)),A=!d&&!(Number.isFinite(e)&&Number.isFinite(r)&&r>0);if(d)return t.jsx(vt,{height:i});if(A)return t.jsx(yt,{height:i,text:u});const $=Zn(h,f),N=ln(h,f),T=Math.max(0,r-e),x=a.length>0?Lr(a,l)??h:h,y=ln(x,f),L=m&&a.length>1?Math.max(100,i-110):0;return t.jsxs("div",{className:`bonsaif-chart bonsaif-ram-chart w-full ${c}`,role:"group","aria-label":v,children:[t.jsxs("div",{className:"bonsaif-metric-head",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"bonsaif-metric-kicker",children:g}),t.jsxs("div",{className:"flex items-baseline gap-2",children:[t.jsx("span",{className:"bonsaif-metric-value",style:{color:N},children:$r(h,h<10?1:0)}),t.jsxs("span",{className:"text-sm tabular-nums",style:{color:"var(--text-secondary)"},children:[Ar(e)," / ",Ar(r)]})]})]}),t.jsx("div",{className:"bonsaif-metric-badge",style:{color:N,background:`color-mix(in srgb, ${N} 14%, transparent)`},children:$==="danger"?"Crítico":$==="warning"?"Alto":"Normal"})]}),t.jsxs("div",{className:"mb-2",children:[t.jsx("div",{className:"h-2 w-full overflow-hidden rounded-sm",style:{background:"color-mix(in srgb, var(--border) 55%, transparent)"},role:"progressbar","aria-valuenow":Math.round(h),"aria-valuemin":0,"aria-valuemax":100,"aria-label":`${g} ${$r(h,0)}`,children:t.jsx("div",{className:"h-full rounded-sm transition-[width] duration-300",style:{width:`${h}%`,background:`linear-gradient(90deg, ${N}, color-mix(in srgb, ${N} 55%, #38bdf8))`}})}),t.jsxs("div",{className:"mt-2 flex flex-wrap gap-x-4 gap-y-1 text-[11px] tabular-nums",style:{color:"var(--text-muted)"},children:[t.jsxs("span",{children:[t.jsx("span",{className:"font-medium",style:{color:"var(--text-main)"},children:"Usada"})," ",Ar(e)]}),n!=null&&Number.isFinite(n)?t.jsxs("span",{children:[t.jsx("span",{className:"font-medium",style:{color:"var(--text-main)"},children:"Caché"})," ",Ar(n)]}):null,t.jsxs("span",{children:[t.jsx("span",{className:"font-medium",style:{color:"var(--text-main)"},children:"Libre"})," ",Ar(T)]})]})]}),m&&a.length>1?t.jsx(ta,{data:a,xKey:s,series:[{key:l,label:"Uso",color:y}],height:L,yDomain:[0,100],showLegend:!1,showTooltip:b,valueFormat:w=>$r(w,0),ariaLabel:`${v} — historial`,opacity:.22,margin:{top:8,right:8,bottom:4,left:0}}):null]})}const vb="color-mix(in srgb, var(--primary) 25%, #38bdf8)",yb="color-mix(in srgb, var(--primary) 20%, #2dd4bf)";function xb({data:e,timeKey:r="t",inboundKey:n="in",outboundKey:a="out",inbound:s,outbound:l,unit:i="bytes",inboundLabel:c="Entrada",outboundLabel:d="Salida",inboundColor:u=vb,outboundColor:m=yb,height:b=240,className:f="",loading:g=!1,emptyText:v="Sin datos de red",showLegend:k=!1,showTooltip:h=!0,label:A="Network",ariaLabel:$="Tráfico de red"}){const N=s??Lr(e,n)??0,T=l??Lr(e,a)??0,x=!g&&e.length===0;if(g)return t.jsx(vt,{height:b});if(x)return t.jsx(yt,{height:b,text:v});const y=W=>Wl(W,i),w=Math.max(140,b-76);return t.jsxs("div",{className:`bonsaif-chart bonsaif-network-chart w-full ${f}`,role:"group","aria-label":$,children:[t.jsx("div",{className:"bonsaif-network-header relative z-10 mb-4 grid gap-3 border-b pb-3 sm:grid-cols-[minmax(0,1.4fr)_minmax(0,1fr)]",style:{borderColor:"var(--border)"},children:t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"bonsaif-metric-kicker",children:A}),t.jsxs("div",{className:"mt-2 grid grid-cols-2 gap-5 sm:max-w-lg",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",style:{color:"var(--text-muted)"},children:[t.jsx("span",{className:"h-3 w-1.5 shrink-0 rounded-sm",style:{background:u},"aria-hidden":!0}),c]}),t.jsx("div",{className:"mt-1 truncate text-xl font-bold tabular-nums leading-tight tracking-tight",style:{color:u},title:y(N),children:y(N)})]}),t.jsxs("div",{className:"min-w-0 pl-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",style:{color:"var(--text-muted)"},children:[t.jsx("span",{className:"h-3 w-1.5 shrink-0 rounded-sm",style:{background:m},"aria-hidden":!0}),d]}),t.jsx("div",{className:"mt-1 truncate text-lg font-semibold tabular-nums leading-tight tracking-tight opacity-95",style:{color:m},title:y(T),children:y(T)})]})]})]})}),t.jsx("div",{className:"bonsaif-network-plot relative z-0",children:t.jsx(ta,{data:e,xKey:r,series:[{key:n,label:c,color:u},{key:a,label:d,color:m}],height:w,showLegend:k,showTooltip:h,valueFormat:y,ariaLabel:$,opacity:.18,margin:{top:8,right:8,bottom:4,left:4}})})]})}const Ql=["primeSuiteOrigin","primeAuthOrigin","primeSuiteAppUrl"],Jl=["primeSuiteOrigin","primeSuiteProjectKey"];function wb(){if(typeof window>"u")return"*";try{if(window.parent===window)return"*";const e=new URLSearchParams(window.location.search);for(const r of Ql){const n=e.get(r);if(n){const a=aa(n);if(a)return a}}if(typeof sessionStorage<"u")for(const r of Jl){const n=sessionStorage.getItem(r);if(n)try{const a=new URL(n);if(a.origin&&a.origin!==window.location.origin)return a.origin}catch{const a=aa(n);if(a)return a}}if(document.referrer){const r=aa(document.referrer);if(r&&r!==window.location.origin)return r}return"*"}catch{return"*"}}function Nb(){if(typeof window>"u")return"self";try{if(window.parent===window)return"self";const e=new URLSearchParams(window.location.search);for(const r of Ql)if(e.get(r))return"query";if(typeof sessionStorage<"u"){for(const r of Jl)if(sessionStorage.getItem(r))return"sessionStorage"}if(document.referrer){const r=aa(document.referrer);if(r&&r!==window.location.origin)return"referrer"}return"wildcard"}catch{return"wildcard"}}function aa(e){if(!e)return null;const r=e.trim().replace(/\/+$/,"");if(!r)return null;if(/^https?:\/\/[^/]+$/.test(r))return r;try{return new URL(r).origin}catch{return null}}function kb(e){const[r,n]=o.useState({}),[a,s]=o.useState(!1),l=o.useCallback(u=>a||r[u]?e[u]:void 0,[e,a,r]),i=o.useCallback(u=>{n(m=>({...m,[u]:!0}))},[]),c=o.useCallback(()=>{s(!0)},[]),d=o.useCallback(()=>{n({}),s(!1)},[]);return{submitted:a,touchedFields:r,getFieldError:l,touchField:i,submit:c,reset:d}}Object.defineProperty(V,"toast",{enumerable:!0,get:()=>Ma.toast}),V.Alert=Qi,V.AreaChart=ta,V.AuthShell=Hl,V.AutoGrowTextarea=gl,V.AutoGrowTextareaField=Gu,V.BarChart=Rf,V.BonsaifButton=Di,V.BonsaifUIToaster=Xf,V.BulletChart=pb,V.Button=Ue,V.CHART_PALETTE=sn,V.CalendarPicker=rc,V.ChartCard=Kf,V.Checkbox=Nn,V.CodeBlock=lc,V.ComboChart=ab,V.CompactFilterSelect=dc,V.CompactSearchInput=cc,V.ConfirmDialog=mc,V.CopyButton=La,V.CopyLinkButton=vc,V.CpuChart=hb,V.DataSheets=Uc,V.DataTable=is,V.DateRangePicker=Gc,V.DonutChart=tb,V.Drawer=od,V.DropdownMenu=nd,V.DynamicDetailTabs=Gi,V.EmailField=Td,V.EmptyState=Ad,V.FieldHelperFooter=wr,V.FieldLabelInfo=xr,V.FieldLayoutEditor=Bd,V.FileUpload=Od,V.FormField=In,V.FunnelChart=fb,V.GaugeChart=bb,V.GlobalScrollbars=$l,V.ImageLightbox=Ts,V.ImageLightboxHost=Vd,V.InputField=Ya,V.LineChart=Jf,V.LoadingState=Yo,V.MentionTextEditor=ml,V.MicroserviceFrame=jf,V.Modal=Oa,V.MouseTooltip=Yt,V.MultiDateCalendar=Jc,V.MultiSelect=Xd,V.NetworkChart=xb,V.NumberField=Kd,V.PageHeader=_f,V.PageSearchInput=Wo,V.Pagination=Zd,V.PhoneField=Jd,V.PieChart=eb,V.PrimeAuthRouteShell=zf,V.PrimeSuiteChatFrame=qf,V.RadioGroup=Rd,V.RamChart=gb,V.RichTextEditor=Ou,V.SearchableSelect=ar,V.SectionPanel=Hu,V.Sparkline=nb,V.StatusBadge=Pu,V.StatusSelect=qu,V.StepWizard=Vu,V.TableSkeleton=wn,V.Tabs=Uu,V.TagInput=of,V.TextInput=Dn,V.Textarea=vl,V.TextareaField=ef,V.TimeField=mf,V.TimePicker=Cl,V.Toggle=hf,V.TruncatedWithTooltip=Pt,V.UserAvatar=Ol,V.WaterfallChart=ob,V.YearMultiDateCalendar=ed,V.buildMentionQueryRegex=Ks,V.clearMentionChipSelection=Er,V.cn=Vt,V.configureBonsaifUI=wc,V.dedupeMentions=Rs,V.defaultValueFormat=gt,V.deleteEditorSelection=il,V.describeParentTargetOrigin=Nb,V.emailFormat=ud,V.ensureMentionChipTrailingSpaces=lo,V.extractMentionUsernames=so,V.filterSelfMentions=Mu,V.findMentionChipAfterCaret=dl,V.findMentionChipBeforeCaret=cl,V.findMentionChipsInSelection=uo,V.findMentionTriggerInEditor=ao,V.formatBytes=Ar,V.formatPercent=$r,V.formatRate=Wl,V.getBonsaifUIConfig=Nc,V.getDataTablePreferencesEndpoint=Ha,V.getEditorPlainText=co,V.getPlainTextOffset=qn,V.highlightMentions=el,V.htmlToText=Qs,V.insertMentionInEditor=rl,V.isMentionTriggerBoundary=Zs,V.isPlainOffsetInsideMentionChip=Gs,V.isValidEmail=qa,V.isValidPhone=Ua,V.locateTextOffset=Cr,V.matches=gd,V.maxLength=md,V.maxValue=hd,V.mentionDisplayLabel=Js,V.minLength=bd,V.minValue=pd,V.normalizeUsername=oo,V.openImageLightboxFromEvent=Es,V.phoneCountryCodeOptions=Ls,V.phoneFormat=fd,V.placeCaretAtTextOffset=nl,V.removeMentionChip=Yn,V.required=dd,V.resetBonsaifUIConfig=kc,V.resolveMentions=Eu,V.resolveParentTargetOrigin=wb,V.selectAllEditorContents=sl,V.selectMentionChip=ol,V.selectionIncludesNonChipText=ll,V.seriesColor=zl,V.setBonsaifDataTablePreferencesEndpoint=Sc,V.syncMentionChipSelectionHighlight=Vn,V.toneColor=Lt,V.usageColor=ln,V.usageTone=Zn,V.useValidationVisibility=kb,V.validateForm=vd,Object.defineProperty(V,Symbol.toStringTag,{value:"Module"})}));