'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$2 = require('./index-1a9e1965.js');
require('./index-451ca284.js');
const index = require('./index-36cf3884.js');

const sv = {
  Save: "Spara",
  Cancel: "Avbryt",
  primary: "primär",
  cellphone: "mobiltelefon",
  landline: "fast telefon",
  "Please enter a valid phone number.": "Ange ett giltigt telefonnummer.",
  "Phone number": "Telefonnummer",
};

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

const styleCss = ".sc-payfunc-phone-number-input-h{margin-top:.5em;display:block}smoothly-submit.sc-payfunc-phone-number-input,smoothly-submit.sc-payfunc-phone-number-input>button.sc-payfunc-phone-number-input{background-color:transparent;border:none;cursor:pointer;color:transparent;width:auto;float:right;margin-top:.2em}smoothly-input.sc-payfunc-phone-number-input{border:1px solid rgb(var(--smoothly-medium-color))}form.sc-payfunc-phone-number-input{display:flex;flex-flow:row;flex-wrap:wrap}form.sc-payfunc-phone-number-input>*.sc-payfunc-phone-number-input:not(smoothly-icon){width:100%}form.sc-payfunc-phone-number-input>tr.sc-payfunc-phone-number-input>span.sc-payfunc-phone-number-input>smoothly-icon.sc-payfunc-phone-number-input{float:left;margin-right:.2em}form.sc-payfunc-phone-number-input>tr.sc-payfunc-phone-number-input>span.sc-payfunc-phone-number-input{float:left;margin-right:1em;padding-bottom:.5em;padding-top:.5em;font-size:.9em}";

const PayfuncPhoneNumberInput = class {
  constructor(hostRef) {
    index$1.registerInstance(this, hostRef);
    this.add = index$1.createEvent(this, "add", 7);
    this.edit = index$1.createEvent(this, "edit", 7);
    this.notice = index$1.createEvent(this, "notice", 7);
    this.types = [];
    this.type = this.types[0];
    this.mode = "edit";
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  onSubmit(e) {
    const value = e.detail.phone;
    if (value) {
      if (this.mode == "add")
        this.add.emit({ type: this.type, value });
      else
        this.edit.emit(value);
    }
    else
      this.notice.emit(index$2.Notice.failed(this.t("Please enter a valid phone number.")));
  }
  onCancel() {
    this.edit.emit(this.value);
  }
  onSelectionChanged(e) {
    this.type = e.detail.value;
  }
  toUpperCase(value) {
    return value.charAt(0).toUpperCase() + value.slice(1);
  }
  render() {
    const t = this.t;
    return (index$1.h("form", null, this.mode == "add" ? (index$1.h("smoothly-select", { background: "transparent" }, this.types.map(option => this.type == option ? (index$1.h("option", { value: option, selected: true }, this.toUpperCase(t(option)))) : (index$1.h("option", { value: option }, this.toUpperCase(t(option))))))) : ([]), index$1.h("smoothly-input", { type: "phone", name: "phone", value: this.value }, this.mode == "add" ? t("Phone number") : t(this.type)), index$1.h("div", null, index$1.h("smoothly-submit", { prevent: true, onSubmit: (e) => this.onSubmit(e) }, index$1.h("smoothly-icon", { name: "checkmark-circle", toolTip: t("Save"), color: "success", fill: "clear", size: "small" })), index$1.h("smoothly-submit", { prevent: true, onSubmit: () => this.onCancel() }, index$1.h("smoothly-icon", { name: "close-circle", toolTip: t("Cancel"), color: "light", fill: "clear", size: "small" })))));
  }
  get element() { return index$1.getElement(this); }
};
PayfuncPhoneNumberInput.style = styleCss;

exports.payfunc_phone_number_input = PayfuncPhoneNumberInput;
