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