"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2615],{32615:(e,t,r)=>{r.r(t),r.d(t,{ApiProvider:()=>y,useApiContext:()=>d,useServerSelectContext:()=>f});var n=r(95155),o=r(12115),a=r(71797),i=r(77944);let l={"application/json":{encode:e=>JSON.stringify(e.body),generateExample:(e,t)=>s(e.body,"application/json",t)},"application/xml":{encode:e=>i(e.body,{compact:!0,spaces:2}),generateExample:(e,t)=>s(e.body,"application/xml",t)},"application/x-ndjson":{encode:e=>Array.isArray(e.body)?e.body.map(e=>JSON.stringify(e)).join("\n"):JSON.stringify(e.body),generateExample:(e,t)=>s(e.body,"application/x-ndjson",t)},"application/x-www-form-urlencoded":{encode(e){if("object"!=typeof e.body)throw Error(`Input value must be object, received: ${typeof e.body}`);let t=new URLSearchParams;for(let r in e.body)t.set(r,String(e.body[r]));return t},generateExample:(e,t)=>"js"===t.lang?`const body = new URLSearchParams(${JSON.stringify(e.body,null,2)})`:s(e.body,"application/x-www-form-urlencoded",t)},"multipart/form-data":{encode(e){let t=new FormData,r=e.body;if("object"!=typeof r||!r)throw Error(`Unsupported body type: ${typeof r}, expected: object`);for(let e in r){let n=r[e];if(!(null==n||Number.isNaN(n)))if(Array.isArray(n))for(let r of n)null!=r&&(r instanceof File?t.append(e,r,r.name):r instanceof Blob?t.append(e,r,"blob"):"object"==typeof r?t.append(e,JSON.stringify(r)):t.append(e,String(r)));else n instanceof File?t.set(e,n,n.name):n instanceof Blob?t.set(e,n,"blob"):"object"==typeof n?t.set(e,JSON.stringify(n)):t.set(e,String(n))}return t},generateExample(e,t){if("python"===t.lang)return`body = ${JSON.stringify(e.body,null,2)}`;let r=[];if("js"===t.lang)for(let[t,n]of(r.push("const body = new FormData();"),Object.entries(e.body)))r.push(`body.set(${t}, ${JSON.stringify((0,a.N)(n))})`);if("go"===t.lang){let{addImport:n}=t;for(let[t,o]of(n("mime/multipart"),n("bytes"),r.push("body := new(bytes.Buffer)"),r.push("mp := multipart.NewWriter(payload)"),Object.entries(e.body))){if(!o)continue;let e=(0,a.$)((0,a.N)(o,"application/json"),"`");r.push(`mp.WriteField("${t}", ${e})`)}}if("java"===t.lang){let{addImport:e}=t;e("java.net.http.HttpRequest.BodyPublishers"),r.push("var body = BodyPublishers.ofByteArray(new byte[] { ... });")}if("csharp"===t.lang&&r.push("var body = new MultipartFormDataContent();"),r.length>0)return r.join("\n")}},"application/octet-stream":{encode:e=>e.body,generateExample(){}}};function s(e,t,r){if("js"===r.lang)return"application/json"===t?`const body = JSON.stringify(${JSON.stringify(e,null,2)})`:`const body = ${(0,a.$)((0,a.N)(e,t),"`")}`;if("python"===r.lang)return"application/json"===t?`body = ${JSON.stringify(e,null,2)}`:`body = ${(0,a.$)((0,a.N)(e,t),'"""')}`;if("go"===r.lang){let{addImport:n}=r;return n("strings"),`body := strings.NewReader(${(0,a.$)((0,a.N)(e,t),"`")})`}if("java"===r.lang){let{addImport:n}=r;return n("java.net.http.HttpRequest.BodyPublishers"),`var body = BodyPublishers.ofString(${(0,a.$)((0,a.N)(e,t),'"""')});`}if("csharp"===r.lang){let r=`
${(0,a.N)(e,t)}
`;return`var body = new StringContent(${(0,a.$)(r,'"""')}, Encoding.UTF8, "${t}");`}}let p=(0,o.createContext)(null),u=(0,o.createContext)(null);function d(){let e=(0,o.useContext)(p);if(!e)throw Error("Component must be used under <ApiProvider />");return e}function f(){let e=(0,o.useContext)(u);if(!e)throw Error("Component must be used under <ApiProvider />");return e}function y(e){let{defaultBaseUrl:t,children:r,servers:a,mediaAdapters:i,shikiOptions:s}=e,[d,f]=(0,o.useState)(()=>{let e=t?a.find(e=>e.url===t):a.at(0);return e?{url:e.url,variables:c(e)}:null});return(0,o.useEffect)(()=>{let e=localStorage.getItem("apiBaseUrl");if(e)try{let t=JSON.parse(e);if(!t||"object"!=typeof t)return;f(t)}catch(e){}},[]),(0,n.jsx)(p.Provider,{value:(0,o.useMemo)(()=>({shikiOptions:s,mediaAdapters:{...l,...i},servers:a}),[i,a,s]),children:(0,n.jsx)(u.Provider,{value:(0,o.useMemo)(()=>({server:d,setServerVariables(e){f(t=>{if(!t)return null;let r={...t,variables:e};return localStorage.setItem("apiBaseUrl",JSON.stringify(r)),r})},setServer(e){let t=a.find(t=>t.url===e);if(!t)return;let r={url:e,variables:c(t)};localStorage.setItem("apiBaseUrl",JSON.stringify(r)),f(r)}}),[d,a]),children:r})})}function c(e){var t;return Object.fromEntries(Object.entries(null!=(t=e.variables)?t:{}).map(e=>{let[t,r]=e;return[t,r.default]}))}}}]);