import{r as e,c as t,h as s,g as o}from"./p-e964d29c.js";import{E as r}from"./p-121de483.js";import{I as i}from"./p-4f46f4bb.js";import"./p-d636f04c.js";import{N as m}from"./p-363dca49.js";import{C as c}from"./p-11286511.js";import{d as a}from"./p-7b48c7c5.js";const 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..."},n=class{constructor(s){e(this,s),this.createCustomer=t(this,"createCustomer",7),this.notice=t(this,"notice",7),this.close=t(this,"close",7)}componentWillLoad(){this.customerNumber=i.generate(12),this.t=a.create({sv:l},this.element)}async submitCustomer(e){const t={number:e.detail.number,contact:{name:""==e.detail.name?void 0:e.detail.name,email:""==e.detail.email?void 0:e.detail.email},method:[]};this.notice.emit(m.execute(this.t("Creating customer..."),(async()=>{let e;this.close.emit();const s=await c.post("customer/",t);if(r.is(s))e=[!1,this.t("Failed to create customer.")];else{e=[!0,this.t("Customer was created.")];const t=await c.get("customer/");this.createCustomer.emit(t)}return e})))}render(){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:!0,onSubmit:e=>this.submitCustomer(e)},s("smoothly-icon",{toolTip:this.t("Create customer"),name:"add-circle",fill:"clear",size:"medium",color:"success"}))))]}get element(){return o(this)}};n.style=".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}";export{n as ig_customer_create}