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