"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useCodeSamples=void 0;const jotai_1=require("jotai"),services_1=require("../../services"),store_1=require("../../jotai/store"),operation_1=require("../../jotai/operation"),app_1=require("../../jotai/app");function useCodeSamples({payload:e,isWebhook:a,definitionSamples:t,pointer:o}){var s;const{parser:r,options:{codeSamples:n,generatedSamplesMaxDepth:i}}=(0,jotai_1.useAtomValue)(store_1.globalStoreAtom),l=(0,jotai_1.useAtomValue)((0,operation_1.operationStore)(o)),{languages:p}=(0,jotai_1.useAtomValue)(app_1.languageAtom),[g]=(0,jotai_1.useAtomValue)(app_1.environmentAtom),u=new Map(null==p?void 0:p.map((({key:e,order:a})=>[e,a]))),m=t.filter((e=>u.has((0,app_1.getLangKey)(e)))),d=new Set(m.map(app_1.getLangKey));let c=[];if(!a){c=createCodeSamples((null===(s=n.languages)||void 0===s?void 0:s.filter((({lang:e,label:a})=>"Payload"!==e&&!d.has((0,app_1.getLangKey)({lang:e,label:a})))))||[],n,r.definition,i,l,g)}const _=[...m,...c];e&&u.has(e.lang.toLowerCase())&&_.push(Object.assign(Object.assign({},e),{order:u.get(e.lang.toLowerCase())}));const j=_.map((e=>{var a;const t=null!==(a=e.label)&&void 0!==a?a:e.lang;return Object.assign({key:(0,app_1.getLangKey)(e),title:t,order:"number"==typeof u.get(t.toLowerCase())?u.get(t.toLowerCase()):9999},e)})).sort(((e,a)=>e.order-a.order));return{samples:j}}function createCodeSamples(e,{skipOptionalParameters:a,withOAuth2Call:t},o,s,r,n){return e.map((({lang:e,label:i,options:l})=>({lang:e,label:i,get:i=>(0,services_1.getCodeSample)(Object.assign(Object.assign({},i),{lang:e,options:Object.assign(Object.assign({},l),{skipOptionalParameters:a,withOAuth2Call:t,spec:o,generatedPayloadSamplesMaxDepth:s,store:r}),environment:n}))})))}exports.useCodeSamples=useCodeSamples;
//# sourceMappingURL=useCodeSamples.js.map