import{jsx as _jsx}from"react/jsx-runtime";import{useCallback,useEffect,useRef,useState}from"react";import{useAtom}from"jotai";import{Segmented,isUndefined}from"@redocly/theme";import{Dropdown}from"../Dropdown";import{operationStore}from"../../../jotai/operation";const LIMIT_FOR_SEGMENTED=5;function SchemaSelectionComponent({options:e,onChange:o,pointer:t,schema:n,defaultOneOfIdx:r}){var i,a;const[s,l]=useAtom(operationStore(t)),u=null===(a=e[null!==(i=s.activeOneOf[n.pointer])&&void 0!==i?i:r])||void 0===a?void 0:a.value,[d,m]=useState(!1),c=useRef(null);useEffect((()=>{if(!c.current)return;const e=()=>{var e;const o=null===(e=c.current)||void 0===e?void 0:e.querySelectorAll('button[role="tab"]'),t=Array.from(o||[]).some((e=>e.offsetWidth<e.scrollWidth));t!==d&&m(t)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)}),[d,e]);const f=useCallback((({value:e})=>{var t,r;void 0!==e&&(o?o(e):l({activeExampleName:null===(r=null===(t=n.oneOf)||void 0===t?void 0:t[e])||void 0===r?void 0:r.title,activeOneOf:{[n.pointer]:e},requestValues:{body:null}}))}),[o,n.oneOf,n.pointer,l]);return isUndefined(u)?null:e.length>LIMIT_FOR_SEGMENTED||d?_jsx(Dropdown,{options:e,value:u,onChange:f}):_jsx(Segmented,{ref:c,value:u,onChange:f,options:e,size:"small","data-testid":"segmented-schema"})}export const SchemaSelection=SchemaSelectionComponent;
//# sourceMappingURL=SchemaSelection.js.map