import { r as registerInstance, j as createEvent, h, g as getElement } from './index-07845439.js';
import { e as EmailAddresses } from './index-e20749b7.js';
import { d as dist } from './index-63517df5.js';
import './index-b6cf748e.js';
import './_commonjsHelpers-8fe71198.js';
import './index-265fba1f.js';

const sv = {
  Add: "Lägg till",
};

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

const styleCss = ".sc-ig-email-addresses-h{display:block}smoothly-icon.sc-ig-email-addresses{cursor:pointer;float:right;margin-top:-1.5em;padding-bottom:.5em;visibility:hidden}ig-email-address.sc-ig-email-addresses{clear:both}.sc-ig-email-addresses-h:hover smoothly-icon.sc-ig-email-addresses{visibility:visible}";

const IntergiroEmailAddresses = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.changed = createEvent(this, "changed", 7);
    this.editable = true;
    this.adding = false;
  }
  get types() {
    return EmailAddresses.types.filter(type => EmailAddresses.is(this.value) ? !this.value[type] : this.value ? type != "primary" : type);
  }
  get emailAddresses() {
    return EmailAddresses.is(this.value) ? Object.assign({}, this.value) : { primary: this.value };
  }
  componentWillLoad() {
    this.t = create(this.element);
  }
  onEdit(e) {
    const type = e.detail.type;
    delete e.detail.type;
    let result;
    if (!EmailAddresses.is(this.value))
      result = e.detail.value;
    else {
      result = Object.assign({}, this.value);
      result[type] = e.detail.value;
    }
    this.changed.emit((this.value = result));
  }
  onDelete(e) {
    const type = e.detail;
    const result = Object.assign({}, this.emailAddresses);
    delete result[type];
    this.changed.emit((this.value = result));
  }
  onAdd(e) {
    const type = e.detail.type;
    const value = e.detail.value;
    const result = this.emailAddresses;
    result[type] = value;
    this.changed.emit((this.value = result));
    this.adding = false;
  }
  render() {
    return [
      this.adding ? (h("ig-email-input", { onEdit: () => (this.adding = false), types: this.types, mode: "add", onAdd: (e) => this.onAdd(e) })) : ([]),
      this.editable && this.types.length > 0 ? (h("smoothly-icon", { name: "add-circle", toolTip: this.t("Add"), fill: "clear", size: "medium", color: "success", style: this.adding ? { display: "none" } : {}, onClick: () => (this.adding = true) })) : ([]),
      EmailAddresses.is(this.value) ? (EmailAddresses.map(this.value, (type, value) => [
        h("ig-email-address", { value: value, type: type, editable: this.editable, onEdit: (e) => this.onEdit(e), onDelete: (e) => this.onDelete(e) }),
      ])) : this.value ? (h("ig-email-address", { value: this.value, editable: this.editable, onEdit: (e) => this.onEdit(e), onDelete: (e) => this.onDelete(e) })) : ([]),
    ];
  }
  get element() { return getElement(this); }
};
IntergiroEmailAddresses.style = styleCss;

export { IntergiroEmailAddresses as ig_email_addresses };
