import{jsx as m}from"react/jsx-runtime";import{useCallback as h,useEffect as v,useRef as A,useState as T}from"react";import{useAtom as g}from"jotai";import{isUndefined as w}from"@redocly/theme/core/openapi";import{Segmented as I}from"@redocly/theme/components/Segmented/Segmented";import{Dropdown as x}from"../Dropdown/index.js";import{operationStore as y}from"../../../jotai/operation.js";const L=5,R=7;function _({options:t,onChange:r,pointer:u,schema:n,defaultOneOfIdx:d}){const[S,c]=g(y(u)),p=S.activeOneOf[n.pointer]??d,o=t[p]?.value,[i,E]=T(!1),s=A(null);v(()=>{if(!s.current)return;const e=()=>{const O=s.current?.querySelectorAll('button[role="tab"]'),a=Array.from(O||[]).some(l=>l.offsetWidth<l.scrollWidth);a!==i&&E(a)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[i,t]);const f=h(({value:e})=>{e!==void 0&&(r?r(e):c({activeExampleName:n.oneOf?.[e]?.title,activeOneOf:{[n.pointer]:e},requestValues:{body:null}}))},[r,n.oneOf,n.pointer,c]);return w(o)?null:t.length>L||i?m(x,{options:t,value:o,withSearch:t.length>=R,onChange:f}):m(I,{ref:s,value:o,onChange:f,options:t,size:"small","data-testid":"segmented-schema"})}const k=_;export{k as SchemaSelection};
