"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/asyncToGenerator"),t=require("@babel/runtime/regenerator"),r=require("react"),s=require("../utils.js"),a=require("../../types.js"),n=require("../../utils.js"),u=require("./sharedHooks.js"),i=require("./useCloseTemplateMenu.js"),l=require("./useSelectTemplate.js");require("../../../../utils/index.js");var o=require("../../../../utils/notificationToasts.js");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var p=c(e),m=c(t);exports.useCopyTemplate=function(e){var t=u.useGet("set"),c=u.useGet("get"),d=i.useCloseTemplateMenu(),f=l.useSelectTemplate();return r.useCallback(p.default(m.default.mark((function r(){var u,i,l,p,g;return m.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(d(),!(u=s.findTemplate(c,e))){r.next=20;break}return r.next=5,s.ensureTemplateSettings(c,t,u);case 5:return i=r.sent,l=s.setBusy(t,u.id,a.Action.SaveSettings),r.prev=7,p=n.suggestName(i.name,s.getAllTemplates(c))||i.name,r.next=11,s.addTemplate(c,t,{name:p,settings:c().templateSettings||i.settings,metadata:n.getMetadataForCopyOrExport(i)});case 11:g=r.sent,o.showSuccessNotification('"'.concat(i.name,'" template was copied!')),f(g.id),r.next=19;break;case 16:r.prev=16,r.t0=r.catch(7),console.error(r.t0);case 19:l();case 20:case"end":return r.stop()}}),r,null,[[7,16]])}))),[d,c,t,f,e])};
//# sourceMappingURL=useCopyTemplate.js.map
