'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index$1 = require('./index-df541290.js');
const index$5 = require('./index-0a8af373.js');
const index$2 = require('./index-fe328b96.js');
require('./index-5e992066.js');
const index$4 = require('./index-c12b8888.js');
const index = require('./index-b7493032.js');
const index$3 = require('./index-3e5f1089.js');
require('./App-1e388484.js');
require('./index-0b6f1dd9.js');
require('./_commonjsHelpers-10109b76.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 index.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) {
    index$1.registerInstance(this, hostRef);
    this.createCustomer = index$1.createEvent(this, "createCustomer", 7);
    this.notice = index$1.createEvent(this, "notice", 7);
    this.close = index$1.createEvent(this, "close", 7);
  }
  componentWillLoad() {
    this.customerNumber = index$2.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(index$3.Notice.execute(this.t("Creating customer..."), async () => {
      let result;
      this.close.emit();
      const response = await index$4.Connection.post(`customer/`, customer);
      if (!index$5.Error.is(response)) {
        result = [true, this.t("Customer was created.")];
        const customers = await index$4.Connection.get(`customer/`);
        this.createCustomer.emit(customers);
      }
      else
        result = [false, this.t("Failed to create customer.")];
      return result;
    }));
  }
  render() {
    return [
      index$1.h("form", null, index$1.h("section", null, index$1.h("smoothly-input", { name: "number", type: "text", value: this.customerNumber }, this.t("Customer number")), index$1.h("smoothly-input", { name: "name", type: "text" }, this.t("Name"))), index$1.h("section", null, index$1.h("smoothly-input", { name: "email", type: "text" }, this.t("Email")), index$1.h("smoothly-submit", { fill: "clear", prevent: true, onSubmit: (e) => this.submitCustomer(e) }, index$1.h("smoothly-icon", { toolTip: this.t("Create customer"), name: "add-circle", fill: "clear", size: "medium", color: "success" })))),
    ];
  }
  get element() { return index$1.getElement(this); }
};
IntergiroCustomerCreate.style = styleCss;

exports.ig_customer_create = IntergiroCustomerCreate;
