import { r as registerInstance, j as createEvent, h, g as getElement } from './index-07845439.js';
import { E as Error } from './index-38089f62.js';
import { I as Identifier } from './index-265fba1f.js';
import './index-cd3eb450.js';
import { C as Connection } from './index-e20749b7.js';
import { d as dist } from './index-63517df5.js';
import { N as Notice } from './index-f068b00b.js';
import './App-15d9fce3.js';
import './index-b6cf748e.js';
import './_commonjsHelpers-8fe71198.js';

const sv = {
  "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 create(language) {
  return dist.create({
    sv,
  }, language);
}

const styleCss = ".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}";

const IntergiroCustomerCreate = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.createCustomer = createEvent(this, "createCustomer", 7);
    this.notice = createEvent(this, "notice", 7);
    this.close = createEvent(this, "close", 7);
  }
  componentWillLoad() {
    this.customerNumber = Identifier.generate(12);
    this.t = create(this.element);
  }
  async submitCustomer(event) {
    const customer = {
      number: event.detail.number,
      contact: {
        name: event.detail.name == "" ? undefined : event.detail.name,
        email: event.detail.email == "" ? undefined : event.detail.email,
      },
      method: [],
    };
    this.notice.emit(Notice.execute(this.t("Creating customer..."), async () => {
      let result;
      this.close.emit();
      const response = await Connection.post(`customer/`, customer);
      if (!Error.is(response)) {
        result = [true, this.t("Customer was created.")];
        const customers = await Connection.get(`customer/`);
        this.createCustomer.emit(customers);
      }
      else
        result = [false, this.t("Failed to create customer.")];
      return result;
    }));
  }
  render() {
    return [
      h("form", null, h("section", null, h("smoothly-input", { name: "number", type: "text", value: this.customerNumber }, this.t("Customer number")), h("smoothly-input", { name: "name", type: "text" }, this.t("Name"))), h("section", null, h("smoothly-input", { name: "email", type: "text" }, this.t("Email")), h("smoothly-submit", { fill: "clear", prevent: true, onSubmit: (e) => this.submitCustomer(e) }, h("smoothly-icon", { toolTip: this.t("Create customer"), name: "add-circle", fill: "clear", size: "medium", color: "success" })))),
    ];
  }
  get element() { return getElement(this); }
};
IntergiroCustomerCreate.style = styleCss;

export { IntergiroCustomerCreate as ig_customer_create };
