import{i as e,n as t,t as n}from"./jsx-runtime-CXrijb2r.js";import{g as r}from"./main-DyRYhvT3.js";var i=e(t(),1),a=n(),o=2,s=28,c=`(max-width: 900px)`;function l(e){let t=e?.parentElement??null;for(;t;){let e=window.getComputedStyle(t);if([`auto`,`scroll`,`overlay`].includes(e.overflowY))return t;t=t.parentElement}return null}function u({dataRolePrefix:e,selectLabel:t=`Selection`,ariaLabel:n,value:u,emptyOptionLabel:d,options:f,onChange:p,actions:m=[],actionMenuLabel:h=`Actions`}){let g=(0,i.useRef)(null),_=(0,i.useRef)(null),[v,y]=(0,i.useState)(()=>typeof window<`u`&&window.matchMedia(c).matches),[b,x]=(0,i.useState)(null),[S,C]=(0,i.useState)(!1),[w,T]=(0,i.useState)(!1);(0,i.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(c),t=()=>y(e.matches);return t(),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,i.useEffect)(()=>{if(!v){x(null),C(!1),T(!1);return}let e=g.current,t=_.current;if(!e||!t||typeof window>`u`){x(null),C(!1),T(!1);return}let n=e.closest(`.content`),r=l(e)??n,i=e.nextElementSibling instanceof HTMLElement?e.nextElementSibling:e,a=document.querySelector(`[data-role="mobile-topbar"]`),c=null,u=()=>Math.max(r?.scrollTop??0,window.scrollY,e.ownerDocument.documentElement.scrollTop),d=u(),f=null,p=0,m=null,h=()=>{c!==null&&window.cancelAnimationFrame(c),c=window.requestAnimationFrame(()=>{let t=e.getBoundingClientRect(),r=i.getBoundingClientRect(),o=n?.getBoundingClientRect()??null,s=a?.getBoundingClientRect()??null,c=Math.max(o?.top??0,s?.bottom??0,0)+10,l=t.width>0&&r.bottom>c+72?{left:Math.max(t.left,12),right:Math.max(window.innerWidth-t.right,12),top:c}:null,h=u(),g=t.top<=c+4;if(x(e=>!l&&!e||e&&l&&e.left===l.left&&e.right===l.right&&e.top===l.top?e:l),!l||!g){f=null,p=0,m=null,d=h,C(e=>e&&!1),T(e=>e&&!1);return}if(C(e=>e===g?e:g),m){let e=m===`up`;m=null,T(t=>t===e?t:e)}})};h();let y=()=>{let e=u(),t=e-d;if(d=e,Math.abs(t)>=o){let e=t>0?`down`:`up`;f===e?p+=Math.abs(t):(f=e,p=Math.abs(t)),p>=s&&(m=e,p=0)}h()},b=()=>h();return r?.addEventListener(`scroll`,y,{passive:!0}),window.addEventListener(`scroll`,y,{passive:!0}),window.addEventListener(`resize`,b),()=>{c!==null&&window.cancelAnimationFrame(c),r?.removeEventListener(`scroll`,y),window.removeEventListener(`scroll`,y),window.removeEventListener(`resize`,b)}},[v,f.length,u]);let E=b?{left:`${b.left}px`,right:`${b.right}px`,top:`${b.top}px`}:void 0,D=r=>(0,a.jsxs)(`div`,{className:`settings-mobile-subnav__picker`,children:[t?(0,a.jsx)(`span`,{className:`settings-mobile-subnav__label`,children:t}):null,(0,a.jsxs)(`select`,{className:`select-input settings-mobile-subnav__control`,"data-role":r?`${e}-mobile-subnav-select-control-floating`:`${e}-mobile-subnav-select-control`,"aria-label":n,value:u??``,onChange:e=>p(e.target.value),children:[d?(0,a.jsx)(`option`,{value:``,children:d}):null,f.map(e=>(0,a.jsx)(`option`,{value:e.id,disabled:e.disabled,children:e.label},e.id))]})]}),O=()=>(0,a.jsxs)(`div`,{className:`settings-mobile-subnav`,"data-role":`${e}-mobile-subnav`,children:[D(!1),m.length?(0,a.jsx)(`div`,{className:`settings-mobile-subnav__actions`,"data-role":`${e}-mobile-subnav-actions`,children:(0,a.jsx)(r,{actions:m,menuLabel:h,mobileTriggerVariant:`icon`,mobileTriggerIcon:`☰`,mobileTriggerAriaLabel:h,mobileTriggerDataRole:`${e}-mobile-subnav-menu-trigger`})}):null]});return v?(0,a.jsxs)(`div`,{className:`settings-mobile-subnav-shell`,ref:g,"data-role":`${e}-mobile-subnav-shell`,children:[O(),(0,a.jsx)(`div`,{className:`settings-mobile-subnav__sentinel`,ref:_,"aria-hidden":`true`}),b?(0,a.jsx)(`div`,{className:S&&!w?`settings-mobile-subnav-floating-shell settings-mobile-subnav-floating-shell--hidden`:`settings-mobile-subnav-floating-shell`,"data-role":`${e}-mobile-subnav-floating-shell`,"data-scroll-state":S&&w?`visible`:`hidden`,style:E,children:(0,a.jsxs)(`div`,{className:`settings-mobile-subnav settings-mobile-subnav--floating`,"data-role":`${e}-mobile-subnav-floating`,children:[D(!0),m.length?(0,a.jsx)(`div`,{className:`settings-mobile-subnav__actions`,"data-role":`${e}-mobile-subnav-actions-floating`,children:(0,a.jsx)(r,{actions:m,menuLabel:h,mobileTriggerVariant:`icon`,mobileTriggerIcon:`☰`,mobileTriggerAriaLabel:h,mobileTriggerDataRole:`${e}-mobile-subnav-menu-trigger-floating`})}):null]})}):null]}):null}export{u as t};