text: define("core_payment/gateways_modal",["exports","core/modal_factory","core/templates","core/str","./repository","./selectors","core/modal_events","core_payment/events","core/toast","core/notification","./modal_gateways"],(function(_exports,_modal_factory,_templates,_str,_repository,_selectors,_modal_events,_events,_toast,_notification,_modal_gateways){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_modal_factory=_interopRequireDefault(_modal_factory),_templates=_interopRequireDefault(_templates),_selectors=_interopRequireDefault(_selectors),_modal_events=_interopRequireDefault(_modal_events),_events=_interopRequireDefault(_events),_notification=_interopRequireDefault(_notification),_modal_gateways=_interopRequireDefault(_modal_gateways);var _systemImportTransformerGlobalIdentifier="undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:{};function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg),value=info.value}catch(error){return void reject(error)}info.done?resolve(value):Promise.resolve(value).then(_next,_throw)}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise((function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value)}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err)}_next(void 0)}))}}var _ref,_ref3,_ref4,show=(_ref=_asyncToGenerator(regeneratorRuntime.mark((function _callee(rootNode){var _ref2,_ref2$focusOnClose,focusOnClose,modal,rootElement,gateways,context,_yield$Templates$rend,html,js,_args=arguments;return regeneratorRuntime.wrap((function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _ref2=_args.length>1&&void 0!==_args[1]?_args[1]:{},_ref2$focusOnClose=_ref2.focusOnClose,focusOnClose=void 0===_ref2$focusOnClose?null:_ref2$focusOnClose,_context.t0=_modal_factory.default,_context.t1=_modal_gateways.default.TYPE,_context.next=5,(0,_str.get_string)("selectpaymenttype","core_payment");case 5:return _context.t2=_context.sent,_context.next=8,_templates.default.render("core_payment/gateways_modal",{});case 8:return _context.t3=_context.sent,_context.t4={type:_context.t1,title:_context.t2,body:_context.t3},_context.next=12,_context.t0.create.call(_context.t0,_context.t4);case 12:return modal=_context.sent,rootElement=modal.getRoot()[0],(0,_toast.addToastRegion)(rootElement),modal.show(),modal.getRoot().on(_modal_events.default.hidden,(function(){modal.destroy();try{focusOnClose.focus()}catch(e){}})),modal.getRoot().on(_events.default.proceed,(function(e){var gateway=(rootElement.querySelector(_selectors.default.values.gateway)||{value:""}).value;gateway?processPayment(gateway,rootNode.dataset.component,rootNode.dataset.paymentarea,rootNode.dataset.itemid,rootNode.dataset.description).then((function(message){return modal.hide(),_notification.default.addNotification({message:message,type:"success"}),location.href=rootNode.dataset.successurl,message})).catch((function(message){return _notification.default.alert("",message)})):(0,_str.get_string)("nogatewayselected","core_payment").then((function(message){return(0,_toast.add)(message)})).catch(),e.preventDefault()})),rootElement.addEventListener("change",(function(e){e.target.matches(_selectors.default.elements.gateways)&&updateCostRegion(rootElement,rootNode.dataset.cost)})),_context.next=21,(0,_repository.getAvailableGateways)(rootNode.dataset.component,rootNode.dataset.paymentarea,rootNode.dataset.itemid);case 21:return gateways=_context.sent,context={gateways:gateways},_context.next=25,_templates.default.renderForPromise("core_payment/gateways",context);case 25:return _yield$Templates$rend=_context.sent,html=_yield$Templates$rend.html,js=_yield$Templates$rend.js,_templates.default.replaceNodeContents(rootElement.querySelector(_selectors.default.regions.gatewaysContainer),html,js),selectSingleGateway(rootElement),_context.next=32,updateCostRegion(rootElement,rootNode.dataset.cost);case 32:case"end":return _context.stop()}}),_callee)}))),function(_x){return _ref.apply(this,arguments)}),selectSingleGateway=function(root){var gateways=root.querySelectorAll(_selectors.default.elements.gateways);1==gateways.length&&(gateways[0].checked=!0)},updateCostRegion=(_ref3=_asyncToGenerator(regeneratorRuntime.mark((function _callee2(root){var defaultCost,gatewayElement,surcharge,cost,_yield$Templates$rend2,html,js,_args2=arguments;return regeneratorRuntime.wrap((function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:return defaultCost=_args2.length>1&&void 0!==_args2[1]?_args2[1]:"",gatewayElement=root.querySelector(_selectors.default.values.gateway),surcharge=parseInt((gatewayElement||{dataset:{surcharge:0}}).dataset.surcharge),cost=(gatewayElement||{dataset:{cost:defaultCost}}).dataset.cost,_context2.next=6,_templates.default.renderForPromise("core_payment/fee_breakdown",{fee:cost,surcharge:surcharge});case 6:_yield$Templates$rend2=_context2.sent,html=_yield$Templates$rend2.html,js=_yield$Templates$rend2.js,_templates.default.replaceNodeContents(root.querySelector(_selectors.default.regions.costContainer),html,js);case 10:case"end":return _context2.stop()}}),_callee2)}))),function(_x2){return _ref3.apply(this,arguments)}),processPayment=(_ref4=_asyncToGenerator(regeneratorRuntime.mark((function _callee3(gateway,component,paymentArea,itemId,description){var paymentMethod;return regeneratorRuntime.wrap((function(_context3){for(;;)switch(_context3.prev=_context3.next){case 0:return _context3.next=2,"function"==typeof _systemImportTransformerGlobalIdentifier.define&&_systemImportTransformerGlobalIdentifier.define.amd?new Promise((function(resolve,reject){_systemImportTransformerGlobalIdentifier.require(["paygw_".concat(gateway,"/gateways_modal")],resolve,reject)})):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&_systemImportTransformerGlobalIdentifier.require&&"component"===_systemImportTransformerGlobalIdentifier.require.loader?Promise.resolve(require("paygw_".concat(gateway,"/gateways_modal"))):Promise.resolve(_systemImportTransformerGlobalIdentifier["paygw_".concat(gateway,"/gateways_modal")]);case 2:return paymentMethod=_context3.sent,_context3.abrupt("return",paymentMethod.process(component,paymentArea,itemId,description));case 4:case"end":return _context3.stop()}}),_callee3)}))),function(_x3,_x4,_x5,_x6,_x7){return _ref4.apply(this,arguments)}),init=function init(){init.initialised||(init.initialised=!0,document.addEventListener("click",(function(e){var gatewayTrigger=e.target.closest('[data-action="core_payment/triggerPayment"]');gatewayTrigger&&(e.preventDefault(),show(gatewayTrigger,{focusOnClose:e.target}))})))};_exports.init=init,init.initialised=!1}));
  
  //# sourceMappingURL=gateways_modal.min.js.map