import { r as registerInstance, j as createEvent, h, g as getElement } from './index-aeac5cad.js';
import './App-418c0118.js';
import './_commonjsHelpers-91fffb88.js';
import { N as Notice } from './index-4920b0b3.js';
import './index-66cd4113.js';
import { C as Connection } from './index-ec2a4942.js';
import { d as dist } from './index-fdd60c34.js';
import { d as dist$2 } from './index-909faba2.js';
import { d as dist$1 } from './index-6b5931f4.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 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) {
    registerInstance(this, hostRef);
    this.createAccount = createEvent(this, "createAccount", 7);
    this.notice = createEvent(this, "notice", 7);
    this.close = createEvent(this, "close", 7);
  }
  componentWillLoad() {
    this.accountNumber = dist$1.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(Notice.execute(this.t("Creating account..."), async () => {
      let result;
      this.close.emit();
      const response = await Connection.post(`account/`, account);
      if (!dist$2.Error.is(response)) {
        result = [true, this.t("Account was created.")];
        const accounts = await Connection.get(`account/`);
        this.createAccount.emit(accounts);
      }
      else
        result = [false, this.t("Failed to create account.")];
      return result;
    }));
  }
  render() {
    return [
      h("form", null, h("section", null, h("smoothly-input", { name: "accountNumber", type: "text", value: this.accountNumber }, this.t("Account 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.submitAccount(e) }, h("smoothly-icon", { toolTip: this.t("Create account"), name: "add-circle", fill: "clear", size: "medium", color: "success" })))),
    ];
  }
  get element() { return getElement(this); }
};
PayfuncAccountCreate.style = styleCss;

export { PayfuncAccountCreate as payfunc_account_create };
