"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("@babel/runtime/helpers/toConsumableArray"),r=require("@babel/runtime/helpers/asyncToGenerator"),n=require("@babel/runtime/regenerator"),a=require("react"),s=require("../utils.js"),i=require("../../types.js"),o=require("../../../../clients/jsonApi/index.js"),u=require("../Store.js"),l=require("./sharedHooks.js");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var p=c(e),d=c(t),f=c(r),b=c(n);function m(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function O(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?m(Object(r),!0).forEach((function(t){p.default(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):m(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}exports.useOpenPopover=function(){var e=l.useGet("get"),t=l.useGet("set");return a.useCallback(f.default(b.default.mark((function r(){var n,a,l,c,p,f,m,g,y,j,v,P,h,q,T,x,k,w;return b.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(t({isPopoverOpen:!0}),n=e(),a=n.currentActions,l=n.isInitialized,c=n.reloadListOnOpen,p=n.appKey,f=a.some((function(e){return e.action===i.Action.ReloadList})),!l||!c||f){r.next=29;break}return m=s.setBusy(t,0,i.Action.ReloadList),r.prev=5,r.t0=s.dataFormatter,r.next=9,o.getAppSettingsTemplates(p,{per_page:u.perPage,fields:u.baseFields});case 9:return r.t1=r.sent,g=r.t0.deserialize.call(r.t0,r.t1),y=e(),j=y.currentTemplateId,v=y.templateSettings,P=y.onChange,h=y.hooks.getDefaultTemplate,q=y.dataEqualityFn,r.next=14,s.processLoadedTemplates(e,g);case 14:if(T=r.sent,t(T),x=s.findTemplate(e,j),!(k=(null==h?void 0:h([].concat(d.default(e().presetTemplates),d.default(e().loadedTemplates)),{currentTemplateId:j,templateSettings:v,event:"reloadList"}))||x)||!P){r.next=23;break}return r.next=21,s.ensureTemplateSettings(e,t,k);case 21:(w=r.sent).id===(null==x?void 0:x.id)&&q(w,O(O({},w),{},{settings:v}))||(t({currentTemplateId:w.id,templateSettings:w.settings}),P(w,"reloadList"));case 23:r.next=28;break;case 25:r.prev=25,r.t2=r.catch(5),console.error(r.t2);case 28:m();case 29:case"end":return r.stop()}}),r,null,[[5,25]])}))),[e,t])};
//# sourceMappingURL=useOpenPopover.js.map
