import{jsx as m,jsxs as p,Fragment as g}from"react/jsx-runtime";import{memo as h,useCallback as C,useRef as T}from"react";import{useAtom as v}from"jotai";import{SelectLabel as M,SelectWrapper as w}from"../PayloadSamples/index.js";import{Container as x}from"../common/index.js";import{activeMimeNameAtom as A}from"../../jotai/app.js";import{getActiveMediaType as b}from"../../models/index.js";import{useTranslate as j}from"../../hooks/index.js";function S({children:e,withLabel:i,innerRef:r,translate:a}){return e?i?p(w,{ref:r,children:[m(M,{children:a("openapi.contentType","Content type")}),e]}):m(x,{ref:r,children:e}):null}function B({content:e,withLabel:i,renderSelect:r,children:a}){const u=j(),[c,s]=v(A),f=C(({value:o})=>{if(!e||!t.current)return null;const n=t.current.getBoundingClientRect().y;s(o),requestAnimationFrame(()=>{if(!t.current||n==null)return;const y=t.current.getBoundingClientRect().y;window.scrollBy(0,y-n)})},[e,s]),t=T(null);if(!e||!e.mediaTypes||!e.mediaTypes.length)return null;const d=e.mediaTypes.map((o,n)=>({value:o.name,idx:n})),l=b(e,c);return p(g,{children:[m(S,{innerRef:t,withLabel:i,translate:u,children:r({value:l.name,options:d,onChange:f,ariaLabel:"Content type"})}),a(l)]})}const q=h(B);export{q as MediaTypesSwitch};
