var __awaiter=this&&this.__awaiter||function(e,t,r,s){function n(e){return e instanceof r?e:new r((function(t){t(e)}))}return new(r||(r=Promise))((function(r,i){function o(e){try{a(s.next(e))}catch(e){i(e)}}function c(e){try{a(s["throw"](e))}catch(e){i(e)}}function a(e){e.done?r(e.value):n(e.value).then(o,c)}a((s=s.apply(e,t||[])).next())}))};var __generator=this&&this.__generator||function(e,t){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},s,n,i,o;return o={next:c(0),throw:c(1),return:c(2)},typeof Symbol==="function"&&(o[Symbol.iterator]=function(){return this}),o;function c(e){return function(t){return a([e,t])}}function a(o){if(s)throw new TypeError("Generator is already executing.");while(r)try{if(s=1,n&&(i=o[0]&2?n["return"]:o[0]?n["throw"]||((i=n["return"])&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;if(n=0,i)o=[o[0]&2,i.value];switch(o[0]){case 0:case 1:i=o;break;case 4:r.label++;return{value:o[1],done:false};case 5:r.label++;n=o[1];o=[0];continue;case 7:o=r.ops.pop();r.trys.pop();continue;default:if(!(i=r.trys,i=i.length>0&&i[i.length-1])&&(o[0]===6||o[0]===2)){r=0;continue}if(o[0]===3&&(!i||o[1]>i[0]&&o[1]<i[3])){r.label=o[1];break}if(o[0]===6&&r.label<i[1]){r.label=i[1];i=o;break}if(i&&r.label<i[2]){r.label=i[2];r.ops.push(o);break}if(i[2])r.ops.pop();r.trys.pop();continue}o=t.call(e,r)}catch(e){o=[6,e];n=0}finally{s=i=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:true}}};System.register(["./p-e0e8055c.system.js","./p-e02ca473.system.js","./p-b93550e9.system.js","./p-de9b80d1.system.js","./p-69d11bbb.system.js","./p-2cf27486.system.js","./p-b9937edc.system.js"],(function(e){"use strict";var t,r,s,n,i,o,c,a,u;return{setters:[function(e){t=e.r;r=e.c;s=e.h;n=e.g},function(e){i=e.E},function(e){o=e.I},function(){},function(e){c=e.N},function(e){a=e.C},function(e){u=e.d}],execute:function(){var l={"Customer number":"Kundnummer",Name:"Namn",Email:"E-post","Create customer":"Skapa kund","Failed to create customer.":"Kunde inte skapa kund.","Customer was created.":"Kunden skapades.","Creating customer...":"Skapar kund..."};function m(e){return u.create({sv:l},e)}var f=".sc-ig-customer-create-h>form.sc-ig-customer-create{width:100%;-ms-flex-wrap:wrap;flex-wrap:wrap;display:-ms-flexbox;display:flex}section.sc-ig-customer-create{display:-ms-flexbox;display:flex;-ms-flex-positive:1;flex-grow:1}section.sc-ig-customer-create:last-of-type{-ms-flex-positive:2;flex-grow:2;min-width:calc(100% - 45px)}section.sc-ig-customer-create>smoothly-input.sc-ig-customer-create{border:1px solid rgb(var(--smoothly-medium-color));margin-bottom:0.5em;margin-left:-1px;-ms-flex-positive:1;flex-grow:1}section.sc-ig-customer-create:last-of-type>smoothly-submit.sc-ig-customer-create{float:right;margin-bottom:.5em;border:none}section.sc-ig-customer-create:first-of-type{-ms-flex-wrap:wrap;flex-wrap:wrap}section.sc-ig-customer-create:first-of-type>*.sc-ig-customer-create:first-of-type{-ms-flex-positive:1;flex-grow:1;-ms-flex-preferred-size:8em;flex-basis:8em}section.sc-ig-customer-create:first-of-type>*.sc-ig-customer-create:last-of-type{-ms-flex-positive:3;flex-grow:3}smoothly-icon.sc-ig-customer-create{cursor:pointer;float:right}";var p=e("ig_customer_create",function(){function e(e){t(this,e);this.createCustomer=r(this,"createCustomer",7);this.notice=r(this,"notice",7);this.close=r(this,"close",7)}e.prototype.componentWillLoad=function(){this.customerNumber=o.generate(12);this.t=m(this.element)};e.prototype.submitCustomer=function(e){return __awaiter(this,void 0,void 0,(function(){var t;var r=this;return __generator(this,(function(s){t={number:e.detail.number,contact:{name:e.detail.name==""?undefined:e.detail.name,email:e.detail.email==""?undefined:e.detail.email},method:[]};this.notice.emit(c.execute(this.t("Creating customer..."),(function(){return __awaiter(r,void 0,void 0,(function(){var e,r,s;return __generator(this,(function(n){switch(n.label){case 0:this.close.emit();return[4,a.post("customer/",t)];case 1:r=n.sent();if(!!i.is(r))return[3,3];e=[true,this.t("Customer was created.")];return[4,a.get("customer/")];case 2:s=n.sent();this.createCustomer.emit(s);return[3,4];case 3:e=[false,this.t("Failed to create customer.")];n.label=4;case 4:return[2,e]}}))}))})));return[2]}))}))};e.prototype.render=function(){var e=this;return[s("form",null,s("section",null,s("smoothly-input",{name:"number",type:"text",value:this.customerNumber},this.t("Customer number")),s("smoothly-input",{name:"name",type:"text"},this.t("Name"))),s("section",null,s("smoothly-input",{name:"email",type:"text"},this.t("Email")),s("smoothly-submit",{fill:"clear",prevent:true,onSubmit:function(t){return e.submitCustomer(t)}},s("smoothly-icon",{toolTip:this.t("Create customer"),name:"add-circle",fill:"clear",size:"medium",color:"success"}))))]};Object.defineProperty(e.prototype,"element",{get:function(){return n(this)},enumerable:false,configurable:true});return e}());p.style=f}}}));