"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/asyncToGenerator"),t=require("@babel/runtime/regenerator"),r=require("react"),a=require("../utils.js"),s=require("../../types.js"),n=require("./sharedHooks.js"),i=require("./useCloseTemplateMenu.js"),u=require("../../../../clients/jsonApi/index.js");require("../../../../utils/index.js");var o=require("../../../../utils/notificationToasts.js");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=l(e),p=l(t);exports.useDeleteTemplate=function(e){var t=n.useGet("get"),l=n.useGet("set"),d=i.useCloseTemplateMenu(),f=r.useCallback(c.default(p.default.mark((function e(){var r,n,i,c;return p.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(d(),r=t(),n=r.currentTemplateId,!(i=a.removeTemplateFromList(t,l,t().confirmationTargetTemplateId))){e.next=18;break}return c=a.setBusy(l,i.id,s.Action.Delete),e.prev=5,e.next=8,u.deleteAppSettingsTemplate(t().appKey,i.id);case 8:if(i.id!==n){e.next=11;break}return e.next=11,a.selectTemplateOnDeletion(t,l);case 11:o.showSuccessNotification('"'.concat(i.name,'" has been successfully deleted.')),e.next=17;break;case 14:e.prev=14,e.t0=e.catch(5),console.error(e.t0);case 17:c();case 18:case"end":return e.stop()}}),e,null,[[5,14]])}))),[d,t,l]);return n.useConfirmation(s.ConfirmationModalType.DeleteTemplate,f,{confirmationTargetTemplateId:e})};
//# sourceMappingURL=useDeleteTemplate.js.map
