"use strict";function a(b){"@babel/helpers - typeof";return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},a(b)}Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=void 0;var b=l(require("react")),c=j(require("prop-types")),d=require("../utils/common"),e=require("./CodeSnippet"),f=require("./../contexts/ApiHandler/index.js"),g=require("./../contexts/config/index.js"),h=require("lodash"),i=require("../code-snippets/CodeSnippetGenerator");function j(a){return a&&a.__esModule?a:{default:a}}function k(a){if("function"!=typeof WeakMap)return null;var b=new WeakMap,c=new WeakMap;return(k=function(a){return a?c:b})(a)}function l(b,c){if(!c&&b&&b.__esModule)return b;if(null===b||"object"!==a(b)&&"function"!=typeof b)return{default:b};var d=k(c);if(d&&d.has(b))return d.get(b);var e={},f=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var g in b)if("default"!=g&&Object.prototype.hasOwnProperty.call(b,g)){var h=f?Object.getOwnPropertyDescriptor(b,g):null;h&&(h.get||h.set)?Object.defineProperty(e,g,h):e[g]=b[g]}return e["default"]=b,d&&d.set(b,e),e}function m(a,b){return r(a)||q(a,b)||o(a,b)||n()}function n(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function o(a,b){if(a){if("string"==typeof a)return p(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?p(a,b):void 0}}function p(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function q(a,b){var c=null==a?null:"undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(null!=c){var d,e,f=[],g=!0,h=!1;try{for(c=c.call(a);!(g=(d=c.next()).done)&&(f.push(d.value),!(b&&f.length===b));g=!0);}catch(a){h=!0,e=a}finally{try{g||null==c["return"]||c["return"]()}finally{if(h)throw e}}return f}}function r(a){if(Array.isArray(a))return a}function s(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function t(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?s(Object(b),!0).forEach(function(c){u(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):s(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function u(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}var v={requiresClientId:!1,clientIdLocation:null,clientIdName:null,requiresClientSecret:!1,clientSecretLocation:null,clientSecretName:null,requiresBasicAuth:!1,requiresDigestAuth:!1,requiresHobaAuth:!1,requiresScramShaAuth:!1,requiresVapidAuth:!1,requiresNegotiateAuth:!1,requiresMutualAuth:!1,requiresOauth:!1,parametersArray:[],externalApiKeys:{},soapAction:null,contenttype:null,accept:null,selectedSecurityOption:0},w=function(a){var c=a.snippetType,j=a.snippetInfo,k=(0,f.useApi)(),l=k.api,n=k.apiHandler,o=(0,g.useConfig)(),p=(0,b.useMemo)(function(){return t(t(t({},v),o),(0,h.get)(j,"config"))},[o,j]),q=(0,h.get)(p,"options.languages"),r=(0,h.get)(p,"options.defaultLanguage"),s=(0,b.useState)(r),u=m(s,2),w=u[0],x=u[1],y=(0,b.useState)(!0),z=m(y,2),A=z[0],B=z[1],C=(0,b.useState)([]),D=m(C,2),E=D[0],F=D[1],G=(0,b.useState)(null),H=m(G,2),I=H[0],J=H[1],K=(0,b.useRef)(!1);(0,b.useEffect)(function(){return K.current=!0,function(){K.current=!1}},[]),(0,b.useEffect)(function(){if(j&&l){var f=null;if("operation"===c&&j.operation&&j.pathName){var a=j.operation,b=j.pathName,d=j.method,e=j.maxDepth;f=(0,i.getGeneratedOptionsForOperation)(p,a,b,d,q,e,l,n)}f&&"operation"===c&&M((0,i.generateOperationContent)(f).snippets)}else M(null,"Invalid snippet configuration")},[j,c,p,l,n,q]),(0,b.useEffect)(function(){!K.current||!q||q.includes(w)&&(w||r)||x(q[0])},[w,r,q]);var L,M=function(a,b){K.current&&(a?(B(!1),F(a)):b&&(B(!1),J(b)))};E&&E["".concat(w,"Content")]?L=E["".concat(w,"Content")]:I&&(L=I);var N=(0,d.isExpandable)(L,8),O={generating:A,availableCodeLanguages:q,errorText:I,onChangeCodeLanguage:function changeCodeLanguage(a){K.current&&x(a)},activeCodeLanguage:w,showExpander:N,content:L,highlight:!0};return b["default"].createElement(e.CodeSnippet,O)};w.propTypes={operation:c["default"].object,pathName:c["default"].string,method:c["default"].string};var x=w;exports["default"]=x;