import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{memo,useCallback,useRef}from"react";import{useAtom}from"jotai";import{SelectLabel,SelectWrapper}from"../PayloadSamples";import{Container}from"../common";import{activeMimeNameAtom}from"../../jotai/app";import{getActiveMediaType}from"../../models";function Wrapper({children:e,withLabel:t,innerRef:n}){return e?t?_jsxs(SelectWrapper,{ref:n,children:[_jsx(SelectLabel,{children:"Content type"}),e]}):_jsx(Container,{ref:n,children:e}):null}function MediaTypesSwitchComponent({content:e,withLabel:t,renderSelect:n,children:r}){const[i,a]=useAtom(activeMimeNameAtom),o=useCallback((({value:t})=>{if(!e||!m.current)return null;const n=m.current.getBoundingClientRect().y;a(t),requestAnimationFrame((()=>{if(!m.current||null==n)return;const e=m.current.getBoundingClientRect().y;window.scrollBy(0,e-n)}))}),[e,a]),m=useRef(null);if(!e||!e.mediaTypes||!e.mediaTypes.length)return null;const l=e.mediaTypes.map(((e,t)=>({value:e.name,idx:t}))),c=getActiveMediaType(e,i);return _jsxs(_Fragment,{children:[_jsx(Wrapper,{innerRef:m,withLabel:t,children:n({value:c.name,options:l,onChange:o,ariaLabel:"Content type"})}),r(c)]})}export const MediaTypesSwitch=memo(MediaTypesSwitchComponent);
//# sourceMappingURL=MediaTypesSwitch.js.map