'use strict';

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

const index$1 = require('./index-0b1e2673.js');
require('./App-1647a125.js');
require('./_commonjsHelpers-937cd5b3.js');
const index$3 = require('./index-1a9e1965.js');
require('./index-451ca284.js');
const index$4 = require('./index-ab186017.js');
const index = require('./index-36cf3884.js');
const index$5 = require('./index-061d0ccd.js');
const index$2 = require('./index-10a0b195.js');

const sv = {
  "Account number": "Kontonummer",
  Name: "Namn",
  Email: "E-post",
  "Create account": "Skapa konto",
  "Failed to create account.": "Kunde inte skapa konto.",
  "Account was created.": "Kontot skapades.",
  "Creating account...": "Skapar konto...",
};

function create(language) {
  return index.dist.create({
    sv,
  }, language);
}

const styleCss = ".sc-payfunc-account-create-h>form.sc-payfunc-account-create{width:100%;flex-wrap:wrap;display:flex}section.sc-payfunc-account-create{display:flex;flex-grow:1}section.sc-payfunc-account-create:last-of-type{flex-grow:2;min-width:calc(100% - 45px)}section.sc-payfunc-account-create>smoothly-input.sc-payfunc-account-create{border:1px solid rgb(var(--smoothly-medium-color));margin-bottom:0.5em;margin-left:-1px;flex-grow:1}section.sc-payfunc-account-create:last-of-type>smoothly-submit.sc-payfunc-account-create{float:right;margin-bottom:.5em;border:none}section.sc-payfunc-account-create:first-of-type{flex-wrap:wrap}section.sc-payfunc-account-create:first-of-type>*.sc-payfunc-account-create:first-of-type{flex-grow:1;flex-basis:8em}section.sc-payfunc-account-create:first-of-type>*.sc-payfunc-account-create:last-of-type{flex-grow:3}smoothly-icon.sc-payfunc-account-create{cursor:pointer;float:right}";

const PayfuncAccountCreate = class {
  constructor(hostRef) {
    index$1.registerInstance(this, hostRef);
    this.createAccount = index$1.createEvent(this, "createAccount", 7);
    this.notice = index$1.createEvent(this, "notice", 7);
    this.close = index$1.createEvent(this, "close", 7);
  }
  componentWillLoad() {
    this.accountNumber = index$2.dist.Identifier.generate(12);
    this.t = create(this.element);
  }
  async submitAccount(event) {
    const account = {
      number: event.detail.accountNumber,
      customer: {
        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 account..."), async () => {
      let result;
      this.close.emit();
      const response = await index$4.Connection.post(`account/`, account);
      if (!index$5.dist.Error.is(response)) {
        result = [true, this.t("Account was created.")];
        const accounts = await index$4.Connection.get(`account/`);
        this.createAccount.emit(accounts);
      }
      else
        result = [false, this.t("Failed to create account.")];
      return result;
    }));
  }
  render() {
    return [
      index$1.h("form", null, index$1.h("section", null, index$1.h("smoothly-input", { name: "accountNumber", type: "text", value: this.accountNumber }, this.t("Account 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.submitAccount(e) }, index$1.h("smoothly-icon", { toolTip: this.t("Create account"), name: "add-circle", fill: "clear", size: "medium", color: "success" })))),
    ];
  }
  get element() { return index$1.getElement(this); }
};
PayfuncAccountCreate.style = styleCss;

exports.payfunc_account_create = PayfuncAccountCreate;
