import{i as e,n as t,t as n}from"./jsx-runtime-CXrijb2r.js";var r=e(t(),1),i=n(),a=2,o=28;function s(e,t,n){let r=e.filter(e=>!e.hidden);return r.length?r.some(e=>e.id===t)?t:n&&r.some(e=>e.id===n)?n:r[0].id:``}function c(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 l({className:e,header:t,leadingContent:n,tabs:l,ariaLabel:u,dataRolePrefix:d,initialTabId:f,activeTabId:p,onTabChange:m,mobileSectionControl:h=`tabs`}){let g=(0,r.useRef)(null),[_,v]=(0,r.useState)(f??l.find(e=>!e.hidden)?.id??``),[y,b]=(0,r.useState)(null),[x,S]=(0,r.useState)(!0),C=(0,r.useMemo)(()=>l.filter(e=>!e.hidden),[l]),w=s(C,p??_,f);(0,r.useEffect)(()=>{p!==void 0||w===_||v(w)},[p,w,_]),(0,r.useEffect)(()=>{let e=g.current;if(!e||C.length<2||typeof window>`u`){b(null),S(!0);return}let t=e.closest(`.content`),n=c(e)??t,r=null,i=null,s=()=>Math.max(n?.scrollTop??0,window.scrollY,e.ownerDocument.documentElement.scrollTop),l=s(),u=null,d=0,f=null,p=()=>{r!==null&&window.cancelAnimationFrame(r),r=window.requestAnimationFrame(()=>{let t=e.getBoundingClientRect(),n=t.width>0&&t.bottom>96?{left:Math.max(t.left,12),right:Math.max(window.innerWidth-t.right,12)}:null,r=s(),i=!!n&&r>24;if(b(e=>!n&&!e||e&&n&&e.left===n.left&&e.right===n.right?e:n),!i){u=null,d=0,f=null,l=r,S(e=>e===!0?e:!0);return}if(f){let e=f===`up`;f=null,S(t=>t===e?t:e)}})};p();let m=()=>{let e=s(),t=e-l;if(l=e,Math.abs(t)>=a){let e=t>0?`down`:`up`;u===e?d+=Math.abs(t):(u=e,d=Math.abs(t)),d>=o&&(f=e,d=0)}p()},h=()=>p();return n?.addEventListener(`scroll`,m,{passive:!0}),window.addEventListener(`scroll`,m,{passive:!0}),window.addEventListener(`resize`,h),typeof ResizeObserver<`u`&&(i=new ResizeObserver(()=>p()),i.observe(e)),()=>{r!==null&&window.cancelAnimationFrame(r),i?.disconnect(),n?.removeEventListener(`scroll`,m),window.removeEventListener(`scroll`,m),window.removeEventListener(`resize`,h)}},[C.length]);let T=C.find(e=>e.id===w)??C[0]??null,E=y?{left:`${y.left}px`,right:`${y.right}px`}:{left:`12px`,right:`12px`},D=e=>{p===void 0&&v(e),m?.(e)};return(0,i.jsxs)(`section`,{className:[`settings-tabbed-detail`,e].filter(Boolean).join(` `),ref:g,children:[t,n,T?(0,i.jsx)(`section`,{className:`panel task-detail-tabs-panel settings-detail-tabs-panel`,children:(0,i.jsx)(`div`,{className:`task-detail-tabs__body settings-detail-tabs__body`,children:(0,i.jsx)(`div`,{className:`settings-detail-tabpanel`,id:`${d}-tabpanel-${T.id}`,"data-role":`${d}-tabpanel-wrapper-${T.id}`,role:`tabpanel`,"aria-labelledby":`${d}-tab-${T.id}`,children:T.panel})})}):null,C.length>1?(0,i.jsxs)(`div`,{className:[`task-detail-tab-dock`,`task-detail-tab-dock--persistent-settings`,h===`select`?`task-detail-tab-dock--mobile-select`:null,x?null:`task-detail-tab-dock--hidden`].filter(Boolean).join(` `),"data-role":`${d}-tab-dock`,"data-scroll-state":x?`visible`:`hidden`,style:E,children:[(0,i.jsxs)(`label`,{className:`task-detail-section-select`,"data-role":`${d}-section-select-mobile`,children:[(0,i.jsx)(`span`,{className:`task-detail-section-select__label`,children:`Section`}),(0,i.jsx)(`select`,{className:`select-input task-detail-section-select__control`,"data-role":`${d}-section-select-control`,"aria-label":`${u} section`,value:T.id,onChange:e=>D(e.target.value),children:C.map(e=>(0,i.jsx)(`option`,{value:e.id,children:e.label},e.id))})]}),(0,i.jsx)(`div`,{className:`task-detail-tabs task-detail-tabs--dock`,role:`tablist`,"aria-label":u,children:C.map(e=>(0,i.jsx)(`button`,{className:T.id===e.id?`task-detail-tab task-detail-tab--active`:`task-detail-tab`,"data-role":`${d}-tab-${e.id}`,id:`${d}-tab-${e.id}`,role:`tab`,"aria-selected":T.id===e.id,"aria-controls":`${d}-tabpanel-${e.id}`,type:`button`,onClick:()=>D(e.id),children:e.label},e.id))})]}):null]})}export{l as t};