var It=Object.defineProperty;var Mt=(t,r,e)=>r in t?It(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e;var Oe=(t,r,e)=>Mt(t,typeof r!="symbol"?r+"":r,e);import{a as Ie,r as a,j as d,h as jt,f as J,c as $,o as he,e as $e,x as At,y as Be,R as Lt}from"./index-Daq5M5bC.js";import{c as Dt,d as Ot,P as X,a as B,h as te,e as Bt,r as Me,f as Vt,D as Ht,u as Ve}from"./index-B33Yn3RC.js";import{e as Ue,A as Wt,a as je,i as Ft,k as $t,j as Ut,F as qt,f as zt,u as Kt,g as Gt,d as Xt,h as Yt,l as Qt,y as Zt,z as Jt,B as er}from"./user-status-C4MB9Ruf.js";import{a as tr}from"./index-ChHm2POI.js";/**
 * @license lucide-react v0.511.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const rr=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],qe=Ie("chevron-down",rr);/**
 * @license lucide-react v0.511.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const nr=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],or=Ie("chevron-up",nr);/**
 * @license lucide-react v0.511.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const sr=[["path",{d:"M21.42 10.922a1 1 0 0 0-.019-1.838L12.83 5.18a2 2 0 0 0-1.66 0L2.6 9.08a1 1 0 0 0 0 1.832l8.57 3.908a2 2 0 0 0 1.66 0z",key:"j76jl0"}],["path",{d:"M22 10v6",key:"1lu8f3"}],["path",{d:"M6 12.5V16a6 3 0 0 0 12 0v-3.5",key:"1r8lef"}]],yn=Ie("graduation-cap",sr);function He(t,[r,e]){return Math.min(e,Math.max(r,t))}function ar(t){const r=ir(t),e=a.forwardRef((n,o)=>{const{children:c,...s}=n,i=a.Children.toArray(c),l=i.find(lr);if(l){const u=l.props.children,p=i.map(f=>f===l?a.Children.count(u)>1?a.Children.only(null):a.isValidElement(u)?u.props.children:null:f);return d.jsx(r,{...s,ref:o,children:a.isValidElement(u)?a.cloneElement(u,void 0,p):null})}return d.jsx(r,{...s,ref:o,children:c})});return e.displayName=`${t}.Slot`,e}function ir(t){const r=a.forwardRef((e,n)=>{const{children:o,...c}=e;if(a.isValidElement(o)){const s=ur(o),i=dr(c,o.props);return o.type!==a.Fragment&&(i.ref=n?jt(n,s):s),a.cloneElement(o,i)}return a.Children.count(o)>1?a.Children.only(null):null});return r.displayName=`${t}.SlotClone`,r}var cr=Symbol("radix.slottable");function lr(t){return a.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===cr}function dr(t,r){const e={...r};for(const n in r){const o=t[n],c=r[n];/^on[A-Z]/.test(n)?o&&c?e[n]=(...i)=>{const l=c(...i);return o(...i),l}:o&&(e[n]=o):n==="style"?e[n]={...o,...c}:n==="className"&&(e[n]=[o,c].filter(Boolean).join(" "))}return{...t,...e}}function ur(t){var n,o;let r=(n=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:n.get,e=r&&"isReactWarning"in r&&r.isReactWarning;return e?t.ref:(r=(o=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:o.get,e=r&&"isReactWarning"in r&&r.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var pr=[" ","Enter","ArrowUp","ArrowDown"],fr=[" ","Enter"],ae="Select",[we,xe,mr]=Ot(ae),[de,Sn]=Dt(ae,[mr,Ue]),ye=Ue(),[hr,re]=de(ae),[gr,vr]=de(ae),ze=t=>{const{__scopeSelect:r,children:e,open:n,defaultOpen:o,onOpenChange:c,value:s,defaultValue:i,onValueChange:l,dir:u,name:p,autoComplete:f,disabled:b,required:N,form:T}=t,h=ye(r),[v,x]=a.useState(null),[m,g]=a.useState(null),[j,A]=a.useState(!1),U=Kt(u),[E,R]=Ve({prop:n,defaultProp:o??!1,onChange:c,caller:ae}),[H,q]=Ve({prop:s,defaultProp:i,onChange:l,caller:ae}),D=a.useRef(null),z=v?T||!!v.closest("form"):!0,[Y,K]=a.useState(new Set),V=Array.from(Y).map(L=>L.props.value).join(";");return d.jsx(Gt,{...h,children:d.jsxs(hr,{required:N,scope:r,trigger:v,onTriggerChange:x,valueNode:m,onValueNodeChange:g,valueNodeHasChildren:j,onValueNodeHasChildrenChange:A,contentId:je(),value:H,onValueChange:q,open:E,onOpenChange:R,dir:U,triggerPointerDownPosRef:D,disabled:b,children:[d.jsx(we.Provider,{scope:r,children:d.jsx(gr,{scope:t.__scopeSelect,onNativeOptionAdd:a.useCallback(L=>{K(W=>new Set(W).add(L))},[]),onNativeOptionRemove:a.useCallback(L=>{K(W=>{const F=new Set(W);return F.delete(L),F})},[]),children:e})}),z?d.jsxs(gt,{"aria-hidden":!0,required:N,tabIndex:-1,name:p,autoComplete:f,value:H,onChange:L=>q(L.target.value),disabled:b,form:T,children:[H===void 0?d.jsx("option",{value:""}):null,Array.from(Y)]},V):null]})})};ze.displayName=ae;var Ke="SelectTrigger",Ge=a.forwardRef((t,r)=>{const{__scopeSelect:e,disabled:n=!1,...o}=t,c=ye(e),s=re(Ke,e),i=s.disabled||n,l=J(r,s.onTriggerChange),u=xe(e),p=a.useRef("touch"),[f,b,N]=wt(h=>{const v=u().filter(g=>!g.disabled),x=v.find(g=>g.value===s.value),m=xt(v,h,x);m!==void 0&&s.onValueChange(m.value)}),T=h=>{i||(s.onOpenChange(!0),N()),h&&(s.triggerPointerDownPosRef.current={x:Math.round(h.pageX),y:Math.round(h.pageY)})};return d.jsx(Wt,{asChild:!0,...c,children:d.jsx(X.button,{type:"button",role:"combobox","aria-controls":s.contentId,"aria-expanded":s.open,"aria-required":s.required,"aria-autocomplete":"none",dir:s.dir,"data-state":s.open?"open":"closed",disabled:i,"data-disabled":i?"":void 0,"data-placeholder":vt(s.value)?"":void 0,...o,ref:l,onClick:B(o.onClick,h=>{h.currentTarget.focus(),p.current!=="mouse"&&T(h)}),onPointerDown:B(o.onPointerDown,h=>{p.current=h.pointerType;const v=h.target;v.hasPointerCapture(h.pointerId)&&v.releasePointerCapture(h.pointerId),h.button===0&&h.ctrlKey===!1&&h.pointerType==="mouse"&&(T(h),h.preventDefault())}),onKeyDown:B(o.onKeyDown,h=>{const v=f.current!=="";!(h.ctrlKey||h.altKey||h.metaKey)&&h.key.length===1&&b(h.key),!(v&&h.key===" ")&&pr.includes(h.key)&&(T(),h.preventDefault())})})})});Ge.displayName=Ke;var Xe="SelectValue",Ye=a.forwardRef((t,r)=>{const{__scopeSelect:e,className:n,style:o,children:c,placeholder:s="",...i}=t,l=re(Xe,e),{onValueNodeHasChildrenChange:u}=l,p=c!==void 0,f=J(r,l.onValueNodeChange);return te(()=>{u(p)},[u,p]),d.jsx(X.span,{...i,ref:f,style:{pointerEvents:"none"},children:vt(l.value)?d.jsx(d.Fragment,{children:s}):c})});Ye.displayName=Xe;var wr="SelectIcon",Qe=a.forwardRef((t,r)=>{const{__scopeSelect:e,children:n,...o}=t;return d.jsx(X.span,{"aria-hidden":!0,...o,ref:r,children:n||"▼"})});Qe.displayName=wr;var xr="SelectPortal",Ze=t=>d.jsx(Bt,{asChild:!0,...t});Ze.displayName=xr;var ie="SelectContent",Je=a.forwardRef((t,r)=>{const e=re(ie,t.__scopeSelect),[n,o]=a.useState();if(te(()=>{o(new DocumentFragment)},[]),!e.open){const c=n;return c?Me.createPortal(d.jsx(et,{scope:t.__scopeSelect,children:d.jsx(we.Slot,{scope:t.__scopeSelect,children:d.jsx("div",{children:t.children})})}),c):null}return d.jsx(tt,{...t,ref:r})});Je.displayName=ie;var Z=10,[et,ne]=de(ie),yr="SelectContentImpl",Sr=ar("SelectContent.RemoveScroll"),tt=a.forwardRef((t,r)=>{const{__scopeSelect:e,position:n="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:c,onPointerDownOutside:s,side:i,sideOffset:l,align:u,alignOffset:p,arrowPadding:f,collisionBoundary:b,collisionPadding:N,sticky:T,hideWhenDetached:h,avoidCollisions:v,...x}=t,m=re(ie,e),[g,j]=a.useState(null),[A,U]=a.useState(null),E=J(r,S=>j(S)),[R,H]=a.useState(null),[q,D]=a.useState(null),z=xe(e),[Y,K]=a.useState(!1),V=a.useRef(!1);a.useEffect(()=>{if(g)return Ft(g)},[g]),$t();const L=a.useCallback(S=>{const[M,...G]=z().map(_=>_.ref.current),[I]=G.slice(-1),k=document.activeElement;for(const _ of S)if(_===k||(_==null||_.scrollIntoView({block:"nearest"}),_===M&&A&&(A.scrollTop=0),_===I&&A&&(A.scrollTop=A.scrollHeight),_==null||_.focus(),document.activeElement!==k))return},[z,A]),W=a.useCallback(()=>L([R,g]),[L,R,g]);a.useEffect(()=>{Y&&W()},[Y,W]);const{onOpenChange:F,triggerPointerDownPosRef:w}=m;a.useEffect(()=>{if(g){let S={x:0,y:0};const M=I=>{var k,_;S={x:Math.abs(Math.round(I.pageX)-(((k=w.current)==null?void 0:k.x)??0)),y:Math.abs(Math.round(I.pageY)-(((_=w.current)==null?void 0:_.y)??0))}},G=I=>{S.x<=10&&S.y<=10?I.preventDefault():g.contains(I.target)||F(!1),document.removeEventListener("pointermove",M),w.current=null};return w.current!==null&&(document.addEventListener("pointermove",M),document.addEventListener("pointerup",G,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",M),document.removeEventListener("pointerup",G,{capture:!0})}}},[g,F,w]),a.useEffect(()=>{const S=()=>F(!1);return window.addEventListener("blur",S),window.addEventListener("resize",S),()=>{window.removeEventListener("blur",S),window.removeEventListener("resize",S)}},[F]);const[C,y]=wt(S=>{const M=z().filter(k=>!k.disabled),G=M.find(k=>k.ref.current===document.activeElement),I=xt(M,S,G);I&&setTimeout(()=>I.ref.current.focus())}),P=a.useCallback((S,M,G)=>{const I=!V.current&&!G;(m.value!==void 0&&m.value===M||I)&&(H(S),I&&(V.current=!0))},[m.value]),O=a.useCallback(()=>g==null?void 0:g.focus(),[g]),ee=a.useCallback((S,M,G)=>{const I=!V.current&&!G;(m.value!==void 0&&m.value===M||I)&&D(S)},[m.value]),ce=n==="popper"?Te:rt,Q=ce===Te?{side:i,sideOffset:l,align:u,alignOffset:p,arrowPadding:f,collisionBoundary:b,collisionPadding:N,sticky:T,hideWhenDetached:h,avoidCollisions:v}:{};return d.jsx(et,{scope:e,content:g,viewport:A,onViewportChange:U,itemRefCallback:P,selectedItem:R,onItemLeave:O,itemTextRefCallback:ee,focusSelectedItem:W,selectedItemText:q,position:n,isPositioned:Y,searchRef:C,children:d.jsx(Ut,{as:Sr,allowPinchZoom:!0,children:d.jsx(qt,{asChild:!0,trapped:m.open,onMountAutoFocus:S=>{S.preventDefault()},onUnmountAutoFocus:B(o,S=>{var M;(M=m.trigger)==null||M.focus({preventScroll:!0}),S.preventDefault()}),children:d.jsx(Ht,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:c,onPointerDownOutside:s,onFocusOutside:S=>S.preventDefault(),onDismiss:()=>m.onOpenChange(!1),children:d.jsx(ce,{role:"listbox",id:m.contentId,"data-state":m.open?"open":"closed",dir:m.dir,onContextMenu:S=>S.preventDefault(),...x,...Q,onPlaced:()=>K(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:B(x.onKeyDown,S=>{const M=S.ctrlKey||S.altKey||S.metaKey;if(S.key==="Tab"&&S.preventDefault(),!M&&S.key.length===1&&y(S.key),["ArrowUp","ArrowDown","Home","End"].includes(S.key)){let I=z().filter(k=>!k.disabled).map(k=>k.ref.current);if(["ArrowUp","End"].includes(S.key)&&(I=I.slice().reverse()),["ArrowUp","ArrowDown"].includes(S.key)){const k=S.target,_=I.indexOf(k);I=I.slice(_+1)}setTimeout(()=>L(I)),S.preventDefault()}})})})})})})});tt.displayName=yr;var br="SelectItemAlignedPosition",rt=a.forwardRef((t,r)=>{const{__scopeSelect:e,onPlaced:n,...o}=t,c=re(ie,e),s=ne(ie,e),[i,l]=a.useState(null),[u,p]=a.useState(null),f=J(r,E=>p(E)),b=xe(e),N=a.useRef(!1),T=a.useRef(!0),{viewport:h,selectedItem:v,selectedItemText:x,focusSelectedItem:m}=s,g=a.useCallback(()=>{if(c.trigger&&c.valueNode&&i&&u&&h&&v&&x){const E=c.trigger.getBoundingClientRect(),R=u.getBoundingClientRect(),H=c.valueNode.getBoundingClientRect(),q=x.getBoundingClientRect();if(c.dir!=="rtl"){const k=q.left-R.left,_=H.left-k,oe=E.left-_,se=E.width+oe,Se=Math.max(se,R.width),be=window.innerWidth-Z,Ce=He(_,[Z,Math.max(Z,be-Se)]);i.style.minWidth=se+"px",i.style.left=Ce+"px"}else{const k=R.right-q.right,_=window.innerWidth-H.right-k,oe=window.innerWidth-E.right-_,se=E.width+oe,Se=Math.max(se,R.width),be=window.innerWidth-Z,Ce=He(_,[Z,Math.max(Z,be-Se)]);i.style.minWidth=se+"px",i.style.right=Ce+"px"}const D=b(),z=window.innerHeight-Z*2,Y=h.scrollHeight,K=window.getComputedStyle(u),V=parseInt(K.borderTopWidth,10),L=parseInt(K.paddingTop,10),W=parseInt(K.borderBottomWidth,10),F=parseInt(K.paddingBottom,10),w=V+L+Y+F+W,C=Math.min(v.offsetHeight*5,w),y=window.getComputedStyle(h),P=parseInt(y.paddingTop,10),O=parseInt(y.paddingBottom,10),ee=E.top+E.height/2-Z,ce=z-ee,Q=v.offsetHeight/2,S=v.offsetTop+Q,M=V+L+S,G=w-M;if(M<=ee){const k=D.length>0&&v===D[D.length-1].ref.current;i.style.bottom="0px";const _=u.clientHeight-h.offsetTop-h.offsetHeight,oe=Math.max(ce,Q+(k?O:0)+_+W),se=M+oe;i.style.height=se+"px"}else{const k=D.length>0&&v===D[0].ref.current;i.style.top="0px";const oe=Math.max(ee,V+h.offsetTop+(k?P:0)+Q)+G;i.style.height=oe+"px",h.scrollTop=M-ee+h.offsetTop}i.style.margin=`${Z}px 0`,i.style.minHeight=C+"px",i.style.maxHeight=z+"px",n==null||n(),requestAnimationFrame(()=>N.current=!0)}},[b,c.trigger,c.valueNode,i,u,h,v,x,c.dir,n]);te(()=>g(),[g]);const[j,A]=a.useState();te(()=>{u&&A(window.getComputedStyle(u).zIndex)},[u]);const U=a.useCallback(E=>{E&&T.current===!0&&(g(),m==null||m(),T.current=!1)},[g,m]);return d.jsx(Er,{scope:e,contentWrapper:i,shouldExpandOnScrollRef:N,onScrollButtonChange:U,children:d.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:j},children:d.jsx(X.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});rt.displayName=br;var Cr="SelectPopperPosition",Te=a.forwardRef((t,r)=>{const{__scopeSelect:e,align:n="start",collisionPadding:o=Z,...c}=t,s=ye(e);return d.jsx(zt,{...s,...c,ref:r,align:n,collisionPadding:o,style:{boxSizing:"border-box",...c.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});Te.displayName=Cr;var[Er,Ae]=de(ie,{}),Ne="SelectViewport",nt=a.forwardRef((t,r)=>{const{__scopeSelect:e,nonce:n,...o}=t,c=ne(Ne,e),s=Ae(Ne,e),i=J(r,c.onViewportChange),l=a.useRef(0);return d.jsxs(d.Fragment,{children:[d.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:n}),d.jsx(we.Slot,{scope:e,children:d.jsx(X.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:i,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:B(o.onScroll,u=>{const p=u.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:b}=s;if(b!=null&&b.current&&f){const N=Math.abs(l.current-p.scrollTop);if(N>0){const T=window.innerHeight-Z*2,h=parseFloat(f.style.minHeight),v=parseFloat(f.style.height),x=Math.max(h,v);if(x<T){const m=x+N,g=Math.min(T,m),j=m-g;f.style.height=g+"px",f.style.bottom==="0px"&&(p.scrollTop=j>0?j:0,f.style.justifyContent="flex-end")}}}l.current=p.scrollTop})})})]})});nt.displayName=Ne;var ot="SelectGroup",[Tr,Nr]=de(ot),Rr=a.forwardRef((t,r)=>{const{__scopeSelect:e,...n}=t,o=je();return d.jsx(Tr,{scope:e,id:o,children:d.jsx(X.div,{role:"group","aria-labelledby":o,...n,ref:r})})});Rr.displayName=ot;var st="SelectLabel",at=a.forwardRef((t,r)=>{const{__scopeSelect:e,...n}=t,o=Nr(st,e);return d.jsx(X.div,{id:o.id,...n,ref:r})});at.displayName=st;var ge="SelectItem",[Pr,it]=de(ge),ct=a.forwardRef((t,r)=>{const{__scopeSelect:e,value:n,disabled:o=!1,textValue:c,...s}=t,i=re(ge,e),l=ne(ge,e),u=i.value===n,[p,f]=a.useState(c??""),[b,N]=a.useState(!1),T=J(r,m=>{var g;return(g=l.itemRefCallback)==null?void 0:g.call(l,m,n,o)}),h=je(),v=a.useRef("touch"),x=()=>{o||(i.onValueChange(n),i.onOpenChange(!1))};if(n==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return d.jsx(Pr,{scope:e,value:n,disabled:o,textId:h,isSelected:u,onItemTextChange:a.useCallback(m=>{f(g=>g||((m==null?void 0:m.textContent)??"").trim())},[]),children:d.jsx(we.ItemSlot,{scope:e,value:n,disabled:o,textValue:p,children:d.jsx(X.div,{role:"option","aria-labelledby":h,"data-highlighted":b?"":void 0,"aria-selected":u&&b,"data-state":u?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...s,ref:T,onFocus:B(s.onFocus,()=>N(!0)),onBlur:B(s.onBlur,()=>N(!1)),onClick:B(s.onClick,()=>{v.current!=="mouse"&&x()}),onPointerUp:B(s.onPointerUp,()=>{v.current==="mouse"&&x()}),onPointerDown:B(s.onPointerDown,m=>{v.current=m.pointerType}),onPointerMove:B(s.onPointerMove,m=>{var g;v.current=m.pointerType,o?(g=l.onItemLeave)==null||g.call(l):v.current==="mouse"&&m.currentTarget.focus({preventScroll:!0})}),onPointerLeave:B(s.onPointerLeave,m=>{var g;m.currentTarget===document.activeElement&&((g=l.onItemLeave)==null||g.call(l))}),onKeyDown:B(s.onKeyDown,m=>{var j;((j=l.searchRef)==null?void 0:j.current)!==""&&m.key===" "||(fr.includes(m.key)&&x(),m.key===" "&&m.preventDefault())})})})})});ct.displayName=ge;var fe="SelectItemText",lt=a.forwardRef((t,r)=>{const{__scopeSelect:e,className:n,style:o,...c}=t,s=re(fe,e),i=ne(fe,e),l=it(fe,e),u=vr(fe,e),[p,f]=a.useState(null),b=J(r,x=>f(x),l.onItemTextChange,x=>{var m;return(m=i.itemTextRefCallback)==null?void 0:m.call(i,x,l.value,l.disabled)}),N=p==null?void 0:p.textContent,T=a.useMemo(()=>d.jsx("option",{value:l.value,disabled:l.disabled,children:N},l.value),[l.disabled,l.value,N]),{onNativeOptionAdd:h,onNativeOptionRemove:v}=u;return te(()=>(h(T),()=>v(T)),[h,v,T]),d.jsxs(d.Fragment,{children:[d.jsx(X.span,{id:l.textId,...c,ref:b}),l.isSelected&&s.valueNode&&!s.valueNodeHasChildren?Me.createPortal(c.children,s.valueNode):null]})});lt.displayName=fe;var dt="SelectItemIndicator",ut=a.forwardRef((t,r)=>{const{__scopeSelect:e,...n}=t;return it(dt,e).isSelected?d.jsx(X.span,{"aria-hidden":!0,...n,ref:r}):null});ut.displayName=dt;var Re="SelectScrollUpButton",pt=a.forwardRef((t,r)=>{const e=ne(Re,t.__scopeSelect),n=Ae(Re,t.__scopeSelect),[o,c]=a.useState(!1),s=J(r,n.onScrollButtonChange);return te(()=>{if(e.viewport&&e.isPositioned){let i=function(){const u=l.scrollTop>0;c(u)};const l=e.viewport;return i(),l.addEventListener("scroll",i),()=>l.removeEventListener("scroll",i)}},[e.viewport,e.isPositioned]),o?d.jsx(mt,{...t,ref:s,onAutoScroll:()=>{const{viewport:i,selectedItem:l}=e;i&&l&&(i.scrollTop=i.scrollTop-l.offsetHeight)}}):null});pt.displayName=Re;var Pe="SelectScrollDownButton",ft=a.forwardRef((t,r)=>{const e=ne(Pe,t.__scopeSelect),n=Ae(Pe,t.__scopeSelect),[o,c]=a.useState(!1),s=J(r,n.onScrollButtonChange);return te(()=>{if(e.viewport&&e.isPositioned){let i=function(){const u=l.scrollHeight-l.clientHeight,p=Math.ceil(l.scrollTop)<u;c(p)};const l=e.viewport;return i(),l.addEventListener("scroll",i),()=>l.removeEventListener("scroll",i)}},[e.viewport,e.isPositioned]),o?d.jsx(mt,{...t,ref:s,onAutoScroll:()=>{const{viewport:i,selectedItem:l}=e;i&&l&&(i.scrollTop=i.scrollTop+l.offsetHeight)}}):null});ft.displayName=Pe;var mt=a.forwardRef((t,r)=>{const{__scopeSelect:e,onAutoScroll:n,...o}=t,c=ne("SelectScrollButton",e),s=a.useRef(null),i=xe(e),l=a.useCallback(()=>{s.current!==null&&(window.clearInterval(s.current),s.current=null)},[]);return a.useEffect(()=>()=>l(),[l]),te(()=>{var p;const u=i().find(f=>f.ref.current===document.activeElement);(p=u==null?void 0:u.ref.current)==null||p.scrollIntoView({block:"nearest"})},[i]),d.jsx(X.div,{"aria-hidden":!0,...o,ref:r,style:{flexShrink:0,...o.style},onPointerDown:B(o.onPointerDown,()=>{s.current===null&&(s.current=window.setInterval(n,50))}),onPointerMove:B(o.onPointerMove,()=>{var u;(u=c.onItemLeave)==null||u.call(c),s.current===null&&(s.current=window.setInterval(n,50))}),onPointerLeave:B(o.onPointerLeave,()=>{l()})})}),kr="SelectSeparator",ht=a.forwardRef((t,r)=>{const{__scopeSelect:e,...n}=t;return d.jsx(X.div,{"aria-hidden":!0,...n,ref:r})});ht.displayName=kr;var ke="SelectArrow",_r=a.forwardRef((t,r)=>{const{__scopeSelect:e,...n}=t,o=ye(e),c=re(ke,e),s=ne(ke,e);return c.open&&s.position==="popper"?d.jsx(Yt,{...o,...n,ref:r}):null});_r.displayName=ke;var Ir="SelectBubbleInput",gt=a.forwardRef(({__scopeSelect:t,value:r,...e},n)=>{const o=a.useRef(null),c=J(n,o),s=Xt(r);return a.useEffect(()=>{const i=o.current;if(!i)return;const l=window.HTMLSelectElement.prototype,p=Object.getOwnPropertyDescriptor(l,"value").set;if(s!==r&&p){const f=new Event("change",{bubbles:!0});p.call(i,r),i.dispatchEvent(f)}},[s,r]),d.jsx(X.select,{...e,style:{...tr,...e.style},ref:c,defaultValue:r})});gt.displayName=Ir;function vt(t){return t===""||t===void 0}function wt(t){const r=Vt(t),e=a.useRef(""),n=a.useRef(0),o=a.useCallback(s=>{const i=e.current+s;r(i),function l(u){e.current=u,window.clearTimeout(n.current),u!==""&&(n.current=window.setTimeout(()=>l(""),1e3))}(i)},[r]),c=a.useCallback(()=>{e.current="",window.clearTimeout(n.current)},[]);return a.useEffect(()=>()=>window.clearTimeout(n.current),[]),[e,o,c]}function xt(t,r,e){const o=r.length>1&&Array.from(r).every(u=>u===r[0])?r[0]:r,c=e?t.indexOf(e):-1;let s=Mr(t,Math.max(c,0));o.length===1&&(s=s.filter(u=>u!==e));const l=s.find(u=>u.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==e?l:void 0}function Mr(t,r){return t.map((e,n)=>t[(r+n)%t.length])}var jr=ze,yt=Ge,Ar=Ye,Lr=Qe,Dr=Ze,St=Je,Or=nt,bt=at,Ct=ct,Br=lt,Vr=ut,Et=pt,Tt=ft,Nt=ht;const bn=jr,Cn=Ar,Hr=a.forwardRef(({className:t,children:r,...e},n)=>d.jsxs(yt,{ref:n,className:$("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",t),...e,children:[r,d.jsx(Lr,{asChild:!0,children:d.jsx(qe,{className:"h-4 w-4 opacity-50"})})]}));Hr.displayName=yt.displayName;const Rt=a.forwardRef(({className:t,...r},e)=>d.jsx(Et,{ref:e,className:$("flex cursor-default items-center justify-center py-1",t),...r,children:d.jsx(or,{className:"h-4 w-4"})}));Rt.displayName=Et.displayName;const Pt=a.forwardRef(({className:t,...r},e)=>d.jsx(Tt,{ref:e,className:$("flex cursor-default items-center justify-center py-1",t),...r,children:d.jsx(qe,{className:"h-4 w-4"})}));Pt.displayName=Tt.displayName;const Wr=a.forwardRef(({className:t,children:r,position:e="popper",...n},o)=>d.jsx(Dr,{children:d.jsxs(St,{ref:o,className:$("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",t),position:e,...n,children:[d.jsx(Rt,{}),d.jsx(Or,{className:$("p-1",e==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:r}),d.jsx(Pt,{})]})}));Wr.displayName=St.displayName;const Fr=a.forwardRef(({className:t,...r},e)=>d.jsx(bt,{ref:e,className:$("py-1.5 pl-8 pr-2 text-sm font-semibold",t),...r}));Fr.displayName=bt.displayName;const $r=a.forwardRef(({className:t,children:r,...e},n)=>d.jsxs(Ct,{ref:n,className:$("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...e,children:[d.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:d.jsx(Vr,{children:d.jsx(Qt,{className:"h-4 w-4"})})}),d.jsx(Br,{children:r})]}));$r.displayName=Ct.displayName;const Ur=a.forwardRef(({className:t,...r},e)=>d.jsx(Nt,{ref:e,className:$("-mx-1 my-1 h-px bg-muted",t),...r}));Ur.displayName=Nt.displayName;function qr(t){const r=[];let e=[];return t.forEach(n=>{if(n.text.includes(`
`)){const o=n.text.split(`
`);o.forEach((c,s)=>{c&&e.push({...n,text:c}),s<o.length-1&&(r.push(e),e=[])})}else e.push(n)}),e.length>0&&r.push(e),r}function zr(t,r,e){if(t<=r)return 0;if(t>=e)return 1;const n=e-r;return n<=0?1:Math.min(Math.max((t-r)/n,0),1)}const Kr=({item:t,currentTimeMs:r,onWordClick:e,styleVariant:n="neon"})=>{if(!t.words||t.words.length===0||n==="off")return null;const o=qr(t.words),c=typeof e=="function";return d.jsx(d.Fragment,{children:o.map((s,i)=>d.jsx("div",{className:"block w-fit mx-auto whitespace-pre-wrap",children:s.map((l,u)=>{const p=zr(r,l.start,l.end);return d.jsxs("span",{className:"karaoke-word relative inline-block",...c?{onClick:f=>e(l.text,f),role:"button",style:{cursor:"pointer"},"data-quick-preview-word":l.text}:{},children:[d.jsx("span",{className:"relative z-10",children:l.text}),n==="neon"&&d.jsx("span",{className:"karaoke-word-fill karaoke-neon-fill","aria-hidden":"true",style:{clipPath:`inset(0 ${100-p*100}% 0 0)`},children:l.text}),n==="underline"&&d.jsx("span",{className:"karaoke-underline",style:{width:`${p*100}%`,borderRadius:u===0&&u===s.length-1?"0 0 4px 4px":u===0?"0 0 0 4px":u===s.length-1?"0 0 4px 0":"0"}}),n==="highlight"&&d.jsx("span",{className:"karaoke-highlight",style:{width:`${p*100}%`,borderRadius:u===0&&u===s.length-1?"4px":u===0?"4px 0 0 4px":u===s.length-1?"0 4px 4px 0":"0"}})]},`${i}-${u}`)})},i))})};function Gr(t,r){const e=a.useRef(null),[n,o]=a.useState(0);return a.useEffect(()=>{if(!t)return;const c=document.querySelector("video");if(!c)return;const s=()=>{o(c.currentTime*1e3),e.current=requestAnimationFrame(s)};return e.current=requestAnimationFrame(s),()=>{e.current&&cancelAnimationFrame(e.current),e.current=null}},[t,r]),n}const Xr="acquire-language:ai-rpc/v1";function _e(t){try{t.disconnect()}catch{}}function ve(t){const r=typeof t=="string"?t:t instanceof Error?t.message:"Aborted",e=new Error(r);return e.name="AbortError",e}function kt(t){const r=new Error(t.message);return t.name&&(r.name=t.name),t.code&&(r.code=t.code),r}function Yr(t){return{request:(r,e,n)=>Qr(t,r,e,n),stream:(r,e,n)=>Zr(t,r,e,n)}}function Qr(t,r,e,n){return new Promise((o,c)=>{if(n!=null&&n.aborted){c(ve(n.reason));return}const s=he.runtime.connect({name:t});let i=!1;const l=()=>{n&&p&&n.removeEventListener("abort",p),_e(s)},u=f=>{i||(i=!0,f(),l())},p=n?()=>u(()=>c(ve(n.reason))):null;n&&p&&n.addEventListener("abort",p),s.onMessage.addListener(f=>{const b=f;!b||typeof b.kind!="string"||(b.kind==="result"?u(()=>o(b.value)):b.kind==="error"?u(()=>c(kt(b))):(b.kind==="chunk"||b.kind==="end")&&u(()=>c(new Error(`Stream frame received on request call (method=${r}); use stream() instead`))))}),s.onDisconnect.addListener(()=>{u(()=>c(new Error("Port disconnected before result was received")))});try{const f={kind:"invoke",method:r,payload:e};s.postMessage(f)}catch(f){u(()=>c(f instanceof Error?f:new Error(String(f))))}})}async function*Zr(t,r,e,n){if(n!=null&&n.aborted)throw ve(n.reason);const o=he.runtime.connect({name:t}),c=[];let s=null,i=!1;const l=()=>{const p=s;s=null,p==null||p()};o.onMessage.addListener(p=>{const f=p;!f||typeof f.kind!="string"||(c.push(f),l())}),o.onDisconnect.addListener(()=>{i=!0,l()});const u=n?()=>{l(),_e(o)}:null;n&&u&&n.addEventListener("abort",u);try{for(o.postMessage({kind:"invoke",method:r,payload:e});;){if(n!=null&&n.aborted)throw ve(n.reason);if(c.length===0){if(i)throw new Error("Port disconnected before stream completed");await new Promise(f=>{s=f});continue}const p=c.shift();if(p.kind==="chunk")yield p.value;else{if(p.kind==="end")return;if(p.kind==="error")throw kt(p);if(p.kind==="result"){yield p.value;return}}}}finally{n&&u&&n.removeEventListener("abort",u),_e(o)}}function Jr(t){let r=null;return{get(){return r||(r=Yr(t)),r},setForTesting(e){r=e}}}const en=Jr(Xr);function le(){return en.get()}class tn{constructor(r){Oe(this,"server");this.server=r}async validateConnection(){return le().request("validateConnection",{server:this.server})}async translateText(r,e,n){return le().request("translateText",{server:this.server,text:r,targetLanguage:e,sourceLanguage:n})}async getChatResponse(r,e,n,o,c=""){return le().request("getChatResponse",{server:this.server,message:r,word:e,context:n,history:o,targetLanguage:c})}async getWordDefinitionStream(r,e,n,o,c,s){try{const i=le().stream("getWordDefinitionStream",{server:this.server,word:r,context:e,targetLanguage:n},s);for await(const l of i){if(s!=null&&s.aborted)return;o(l)}}catch(i){if(s!=null&&s.aborted)return;c(i instanceof Error?i:new Error(String(i)))}}async getWordQuickDefinitionStream(r,e,n,o,c,s){try{const i=le().stream("getWordQuickDefinitionStream",{server:this.server,word:r,context:e,targetLanguage:n},s);for await(const l of i){if(s!=null&&s.aborted)return;o(l)}}catch(i){if(s!=null&&s.aborted)return;c(i instanceof Error?i:new Error(String(i)))}}async getChatResponseStream(r,e,n,o,c,s){const i=le().stream("getChatResponseStream",{server:this.server,message:r,word:e,context:n,history:o,targetLanguage:c});for await(const l of i)s(l)}}function rn(t){return t.aiServers.find(r=>r.isDefault)||t.aiServers[0]}function nn(t){return new tn(t)}async function on(){try{const t=await $e(),r=rn(t);return r?nn(r):null}catch(t){return console.error("Failed to get current AI service:",t),null}}const ue=12,We=8,sn=({word:t,context:r,anchor:e})=>{const n=a.useRef(null),[o,c]=a.useState(""),[s,i]=a.useState("loading"),[l,u]=a.useState({left:0,top:0,placement:"top",arrowX:0}),[p,f]=a.useState(!1);a.useLayoutEffect(()=>{const h=()=>{const m=n.current;if(!m||!e.isConnected)return;const g=e.getBoundingClientRect(),j=m.getBoundingClientRect(),A=j.width||m.offsetWidth||200,U=j.height||m.offsetHeight||36,E=window.innerWidth,R=window.innerHeight,H=g.left+g.width/2;let q="top",D=g.top-U-10;D<ue&&(q="bottom",D=g.bottom+10),D=Math.max(ue,Math.min(D,R-U-ue));let z=H-A/2;const Y=ue,K=E-A-ue,V=Math.max(Y,Math.min(z,K)),L=We+4,W=A-We-4,F=Math.max(L,Math.min(W,H-V));u({left:V,top:D,placement:q,arrowX:F}),f(!0)};h();const v=window.requestAnimationFrame(h),x=()=>h();return window.addEventListener("resize",x),window.addEventListener("scroll",x,!0),()=>{window.cancelAnimationFrame(v),window.removeEventListener("resize",x),window.removeEventListener("scroll",x,!0)}},[e,o]),a.useEffect(()=>{const h=new AbortController;let v=!1,x=!1;return c(""),i("loading"),(async()=>{var m;try{const g=await on();if(!(g!=null&&g.getWordQuickDefinitionStream)){v||i("unsupported");return}const A=((m=(await $e()).general)==null?void 0:m.nativeLanguage)||"zh-cn",U=At(A).en_name;let E="";if(await g.getWordQuickDefinitionStream(t,r,U,R=>{v||(E+=R,x||(x=!0,i("streaming")),c(E))},R=>{v||i("error")},h.signal),v)return;i(x?"done":"error")}catch{if(v)return;i("error")}})(),()=>{v=!0;try{h.abort()}catch{}}},[t,r]);const b=s==="streaming",N=s==="loading",T=s==="error"||s==="unsupported";return d.jsxs("div",{ref:n,className:$("fixed z-[10000000] pointer-events-none select-none","rounded-xl px-4 sm:px-5 py-2.5 sm:py-3 max-w-[340px] min-w-[100px]","bg-card/95 supports-[backdrop-filter]:bg-card/90 backdrop-blur-xl","ring-1 ring-border/50 border border-border/40","shadow-[-10px_0_30px_-5px_rgba(0,0,0,0.1),-20px_0_50px_-10px_rgba(0,0,0,0.05)]","text-[17px] sm:text-[18px] leading-relaxed text-card-foreground font-medium text-center tracking-wide","transition-opacity duration-150 ease-out",p?"opacity-100":"opacity-0"),style:{left:l.left,top:l.top},role:"tooltip","aria-live":"polite",children:[N&&d.jsxs("span",{className:"inline-flex items-center gap-1.5 text-muted-foreground","aria-label":"Loading definition",children:[d.jsx("span",{className:"qwp-dot"}),d.jsx("span",{className:"qwp-dot qwp-dot-2"}),d.jsx("span",{className:"qwp-dot qwp-dot-3"})]}),!N&&d.jsx("span",{className:"whitespace-pre-wrap break-words",children:T&&!o?d.jsx("span",{className:"text-muted-foreground",children:"…"}):d.jsxs(d.Fragment,{children:[d.jsx("span",{children:o}),b&&d.jsx("span",{className:"inline-block w-[2px] h-[0.95em] align-[-0.1em] ml-0.5 bg-primary cursor-blink","aria-hidden":"true"})]})}),d.jsx("span",{className:$("qwp-arrow",l.placement==="top"?"qwp-arrow-bottom":"qwp-arrow-top"),style:{left:l.arrowX},"aria-hidden":"true"})]})};var Ee,an=(t,r,e)=>Ee??(Ee=new Promise(n=>{const o=s=>{const{data:{cmd:i,scope:l,context:u},ports:p}=s;if(i==="webext-port-offer"&&l===r&&u!==t)return window.removeEventListener("message",o),p[0].onmessage=e,p[0].postMessage("port-accepted"),n(p[0])},c=()=>{const s=new MessageChannel;s.port1.onmessage=i=>{if(i.data==="port-accepted")return window.removeEventListener("message",o),n(s.port1);e==null||e(i)},window.postMessage({cmd:"webext-port-offer",scope:r,context:t},"*",[s.port2])};window.addEventListener("message",o),c()})),cn=t=>{let r,e=!1,n,o;return{enable:()=>e=!0,onMessage:c=>n=c,postMessage:async c=>{if(!e)throw new Error("Communication with window has not been allowed");return ln(r),(await o).postMessage(c)},setNamespace:c=>{if(r)throw new Error("Namespace once set cannot be changed");r=c,o=an(t,c,({data:s})=>n==null?void 0:n(s))}}};function ln(t){if(typeof t!="string"||t.trim().length===0)throw new Error(`webext-bridge uses window.postMessage to talk with other "window"(s) for message routingwhich is global/conflicting operation in case there are other scripts using webext-bridge. Call Bridge#setNamespace(nsps) to isolate your app. Example: setNamespace('com.facebook.react-devtools'). Make sure to use same namespace across all your scripts whereever window.postMessage is likely to be used\``)}var Le=cn("content-script"),De=Zt(),me=Jt("content-script",t=>{t.destination.context==="window"?Le.postMessage(t):De.postMessage(t)});Le.onMessage(t=>{t.origin={context:"window",tabId:null},me.handleMessage(t)});De.onMessage(me.handleMessage);De.onFailure(t=>{if(t.origin.context==="window"){Le.postMessage({type:"error",transactionID:t.transactionId});return}me.endTransaction(t.transactionId)});var{sendMessage:Fe,onMessage:En}=me;er(me);function dn(){const[t,r]=a.useState(null),e=a.useCallback(async()=>{try{const n=await Fe("ACQUIRE_LANGUAGE:AUTH_GET_USER",{},"background");r(!!(n!=null&&n.isAuthenticated))}catch{r(!1)}},[]);return a.useEffect(()=>{var l,u,p;let n=!1;(async()=>{try{const f=await Fe("ACQUIRE_LANGUAGE:AUTH_GET_USER",{},"background");n||r(!!(f!=null&&f.isAuthenticated))}catch{n||r(!1)}})();let o=!1,c;const s=()=>{o||n||(o=!0,c=globalThis.setTimeout(()=>{o=!1,n||e().catch(()=>{})},50))},i=(f,b)=>{try{if(b!=="local")return;Object.keys(f||{}).some(T=>T.startsWith("logto:"))&&s()}catch{}};try{(p=(u=(l=he.storage)==null?void 0:l.onChanged)==null?void 0:u.addListener)==null||p.call(u,i)}catch{}return()=>{var f,b,N;n=!0;try{(N=(b=(f=he.storage)==null?void 0:f.onChanged)==null?void 0:b.removeListener)==null||N.call(b,i)}catch{}c&&globalThis.clearTimeout(c)}},[e]),t}const un=200,pn=80,pe="data-quick-preview-word",fn=(t,r)=>{if(!t||!t.trim())return[];if(typeof Intl<"u"&&"Segmenter"in Intl)try{const n=new Intl.Segmenter(r,{granularity:"word"}),o=[];for(const c of n.segment(t))o.push(c.segment);return o}catch{}const e=t.match(/\s+|\S+/g);return e||[]},Tn=({texts:t,subtitleItems:r,settings:e,onWordClick:n,onMouseEnter:o,onMouseLeave:c,onDoubleClick:s,enableHoverPreview:i,className:l="",style:u={},...p})=>{const f=a.useRef(null),b=!!(r!=null&&r.length&&r.every(w=>Array.isArray(w.words)&&w.words.length>0)),N=typeof p.karaokeTimeMsOverride=="number"?p.karaokeTimeMsOverride:Gr(b,r),T=typeof n=="function",h=dn(),v=(i??T)&&h===!0,[x,m]=a.useState(null),g=a.useRef(null),j=a.useRef(null),[A,U]=a.useState(null),E=a.useCallback(()=>{g.current&&(clearTimeout(g.current),g.current=null)},[]),R=a.useCallback(()=>{j.current&&(clearTimeout(j.current),j.current=null)},[]),H=a.useCallback(()=>{var w;if(r&&r.length>0){const C=[];for(const P of r)P!=null&&P.text?C.push(P.text):(w=P==null?void 0:P.words)!=null&&w.length&&C.push(P.words.map(O=>O.text).join(""));const y=C.join(" ").trim();if(y)return y}return Array.isArray(t)?t.join(" ").trim():""},[r,t]),q=a.useCallback((w,C)=>{R(),!(x&&x.anchor===C)&&(E(),g.current=setTimeout(()=>{if(g.current=null,!C.isConnected)return;const y=Be(w);y&&m({word:y,anchor:C,context:H()})},un))},[H,R,E,x]),D=a.useCallback(()=>{E(),x&&(R(),j.current=setTimeout(()=>{j.current=null,m(null)},pn))},[R,E,x]),z=a.useMemo(()=>r&&r.length>0?r.map(w=>{var C;return w!=null&&w.text?w.text:(C=w==null?void 0:w.words)!=null&&C.length?w.words.map(y=>y.text).join(""):""}).join(""):Array.isArray(t)?t.join(""):"",[t,r]);a.useEffect(()=>{E(),R(),m(null)},[z,E,R]),a.useEffect(()=>()=>{E(),R()},[E,R]),a.useEffect(()=>{if(!v)return;const w=f.current;if(!w)return;const C=w.getRootNode(),y=document.createElement("div");y.setAttribute("data-quick-word-preview-root",""),y.style.position="absolute",y.style.top="0",y.style.left="0",y.style.width="0",y.style.height="0",y.style.pointerEvents="none";const P=C instanceof ShadowRoot?C.querySelector("body")||C.querySelector("html")||C.firstElementChild||C:typeof document<"u"?document.body:C;try{P.appendChild(y)}catch{try{w.appendChild(y)}catch{return}}return U(y),()=>{try{y.remove()}catch{}U(null)}},[v]);const Y=a.useCallback(w=>{var P;if(!v)return;const C=(P=w.target)==null?void 0:P.closest(`[${pe}]`);if(!C)return;const y=C.getAttribute(pe);y&&q(y,C)},[v,q]),K=a.useCallback(w=>{var O;if(!v)return;const C=(O=w.target)==null?void 0:O.closest(`[${pe}]`),y=w.relatedTarget;if(C&&y&&C.contains(y))return;if(y&&y.nodeType===Node.ELEMENT_NODE?y.closest(`[${pe}]`):null){E();return}D()},[E,v,D]);if(!t)return null;const V=(w,C)=>{if(E(),R(),m(null),n){const y=Be(w);y&&n(y,{x:C.clientX,y:C.clientY})}},L=w=>w.split(`
`).map((y,P)=>d.jsx("div",{className:"block w-fit mx-auto",children:fn(y).map((O,ee)=>{const ce=/^\s+$/.test(O);return d.jsx(Lt.Fragment,{children:ce?d.jsx("span",{"aria-hidden":"true",className:"whitespace-pre-wrap",children:O}):d.jsx("span",{...T?{onClick:Q=>V(O,Q),tabIndex:0,role:"button","aria-label":`Click to analyze word: ${O.trim()}`,onKeyDown:Q=>{(Q.key==="Enter"||Q.key===" ")&&(Q.preventDefault(),V(O,Q))},[pe]:O}:{},className:$("relative inline-block px-px rounded-sm",T?["cursor-pointer select-text transition-colors duration-150 ease-out","hover:bg-white/20 hover:text-white","focus:outline-none focus-visible:ring-2 focus-visible:ring-white/70 focus-visible:ring-offset-1 focus-visible:ring-offset-black/40","active:bg-white/25"]:"cursor-default"),children:O})},`${P}-${ee}`)})},P)),W=w=>{if(!s)return;const C=w.target;C&&C.closest('[role="button"]')||s()},F=_t(e.fontSize,10,48);return a.useEffect(()=>{f.current&&(f.current.style.setProperty("--subtitle-font-size",`${F}px`),f.current.style.setProperty("--subtitle-text-color",e.textColor),e.backgroundColor&&typeof e.opacity=="number"?f.current.style.setProperty("--subtitle-line-bg",mn(e.backgroundColor,e.opacity)):f.current.style.removeProperty("--subtitle-line-bg"))},[F,e.textColor,e.backgroundColor,e.opacity]),d.jsxs("div",{id:"subtitle-display","data-testid":"subtitle-display",className:$("subtitle-container font-medium relative text-center px-1.5 mx-auto","max-w-[min(89%,70ch)]","flex flex-col items-center justify-center","transition-colors duration-150 ease-out",l),onMouseEnter:o,onMouseLeave:c,onMouseOver:v?Y:void 0,onMouseOut:v?K:void 0,onDoubleClick:W,ref:f,children:[d.jsx("div",{className:"relative z-10 w-full",children:b&&r?r.map((w,C)=>{var y;return d.jsx("div",{className:$("subtitle-outline"),children:d.jsx("div",{className:"group relative inline-flex flex-col items-center w-full max-w-full mx-auto rounded-md px-2.5 py-1 subtitle-line-bg",children:e.karaokeStyle!=="off"?d.jsx(Kr,{item:w,currentTimeMs:N,styleVariant:e.karaokeStyle,onWordClick:T?(P,O)=>V(P,O):void 0}):L(((y=w.words)==null?void 0:y.map(P=>P.text).join("").trim())||"")})},C)}):t.map((w,C)=>d.jsx("div",{className:$("subtitle-outline"),children:d.jsx("div",{className:"group relative inline-flex flex-col items-center w-full max-w-full mx-auto rounded-md px-2.5 py-1 subtitle-line-bg",children:L(w)})},`${w}-${C}`))}),v&&x&&A&&Me.createPortal(d.jsx(sn,{word:x.word,context:x.context,anchor:x.anchor},`${x.word}-${x.context.length}`),A)]})};function mn(t,r){const e=t.replace("#",""),n=e.length===3?e.split("").map(u=>u+u).join(""):e,o=parseInt(n,16),c=o>>16&255,s=o>>8&255,i=o&255,l=_t(r,0,1);return`rgba(${c}, ${s}, ${i}, ${l})`}function _t(t,r,e){return Math.min(Math.max(t,r),e)}export{tn as B,qe as C,yn as G,bn as S,Hr as a,Cn as b,Wr as c,$r as d,He as e,or as f,Tn as g,Fe as s};
