import{jsx as h,Fragment as D}from"react/jsx-runtime";import{useMemo as C}from"react";import{useAtomValue as _}from"jotai";import{ParametersGroup as S}from"./ParametersGroup.js";import{Body as b}from"./Body.js";import{makeDeepLink as v}from"../../services/index.js";import{useTranslate as Q}from"../../hooks/index.js";import{globalStoreAtom as z}from"../../jotai/store.js";import{getMediaContent as F}from"../../models/mediaContent.js";import{getContentWithLegacyExamples as T}from"../../utils/openapi.js";const p=["path","query","querystring","cookie","header"];function Z({body:i,parameters:t=[],operationId:n,callbackId:u}){const c=Q(),{parser:a,options:q}=_(z),m=(e=>{const o={};return e.forEach(r=>{W(o,r.in,r)}),o})(t),P=m.querystring||[],d=P.filter(e=>e.serializationMime),f=P.filter(e=>!e.serializationMime),l=C(()=>!a||d.length===0?[]:d.map(e=>{const o=e.deps?.operation?.pointer;if(!o)return null;try{const r=a.byRef(o);if(!r?.parameters)return null;const s=r.parameters.find(x=>{const{resolved:M}=a.deref(x);return M.name===e.name&&M.in==="querystring"});if(!s)return null;const{resolved:E}=a.deref(s),L=T(E);return L?{content:F({parser:a,info:L,isRequestType:!0,options:q,data:{operation:e.deps?.operation||{pointer:o},type:"request",absolutePointer:e.absolutePointer||o}}),description:e.description,required:e.required,name:e.name}:null}catch{return null}}).filter(Boolean),[a,q,d]),R={[p[0]]:c("openapi.path","Path"),[p[1]]:c("openapi.query","Query"),[p[2]]:c("openapi.querystring","Query String"),[p[3]]:c("openapi.cookie","Cookies"),[p[4]]:c("openapi.header","Headers")},{content:y,description:k,required:A}=i||{},$=C(()=>{const e=[],o=f.length>0||l.length>0;return p.forEach(r=>{if(!(r==="query"&&o))if(r==="querystring")f.length>0&&e.push({type:"parameters",place:r,params:f});else{const s=m[r];s&&s.length>0&&e.push({type:"parameters",place:r,params:s})}}),l.forEach((r,s)=>{r&&e.push({type:"body",content:r.content,description:r.description,required:r.required,deepLink:g(n,u,`querystring-${r.name}`),key:`querystring-${r.name}-${s}`})}),y&&e.push({type:"body",content:y,description:k,required:A,deepLink:g(n,u),key:"body"}),e},[m,f,l,y,k,A,n,u]);return!i&&!t.length?null:h(D,{children:$.map(e=>e.type==="parameters"?h(S,{title:R[e.place],parameters:e.params,deepLink:g(n,u,e.place)},e.place):h(b,{content:e.content,description:e.description,required:e.required,deepLink:e.deepLink},e.key))})}function W(i,t="",n){i[t]||(i[t]=[]),i[t].push(n)}function g(i,t,n="body"){const u=`${t?`${t}/request/${n}`:`request/${n}`}`;return v(i,u)}export{Z as RequestParameters};
