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