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