"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MediaTypesSwitch=void 0;const jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),jotai_1=require("jotai"),PayloadSamples_1=require("../PayloadSamples"),common_1=require("../common"),app_1=require("../../jotai/app"),models_1=require("../../models");function Wrapper({children:e,withLabel:t,innerRef:r}){return e?t?(0,jsx_runtime_1.jsxs)(PayloadSamples_1.SelectWrapper,{ref:r,children:[(0,jsx_runtime_1.jsx)(PayloadSamples_1.SelectLabel,{children:"Content type"}),e]}):(0,jsx_runtime_1.jsx)(common_1.Container,{ref:r,children:e}):null}function MediaTypesSwitchComponent({content:e,withLabel:t,renderSelect:r,children:n}){const[i,a]=(0,jotai_1.useAtom)(app_1.activeMimeNameAtom),o=(0,react_1.useCallback)((({value:t})=>{if(!e||!l.current)return null;const r=l.current.getBoundingClientRect().y;a(t),requestAnimationFrame((()=>{if(!l.current||null==r)return;const e=l.current.getBoundingClientRect().y;window.scrollBy(0,e-r)}))}),[e,a]),l=(0,react_1.useRef)(null);if(!e||!e.mediaTypes||!e.mediaTypes.length)return null;const s=e.mediaTypes.map(((e,t)=>({value:e.name,idx:t}))),c=(0,models_1.getActiveMediaType)(e,i);return(0,jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment,{children:[(0,jsx_runtime_1.jsx)(Wrapper,{innerRef:l,withLabel:t,children:r({value:c.name,options:s,onChange:o,ariaLabel:"Content type"})}),n(c)]})}exports.MediaTypesSwitch=(0,react_1.memo)(MediaTypesSwitchComponent);
//# sourceMappingURL=MediaTypesSwitch.js.map