import { Component, Element, Event, h, Listen, Prop, State } from "@stencil/core";
import { Notice } from "smoothly";
import * as translation from "./translation";
export class IntergiroEmailInput {
  constructor() {
    this.types = [];
    this.type = this.types[0];
    this.mode = "edit";
  }
  componentWillLoad() {
    this.t = translation.create(this.element);
  }
  onSubmit(e) {
    const value = e.detail.email;
    if (value) {
      if (this.mode == "add")
        this.add.emit({ type: this.type, value });
      else
        this.edit.emit(e.detail.email);
    }
    else
      this.notice.emit(Notice.failed(this.t("Please enter a valid email address.")));
  }
  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 (h("form", null,
      this.mode == "add" ? (h("smoothly-select", { background: "transparent" }, this.types.map(option => this.type == option ? (h("option", { value: option, selected: true }, this.toUpperCase(t(option)))) : (h("option", { value: option }, this.toUpperCase(t(option))))))) : ([]),
      h("smoothly-input", { type: "email", name: "email", value: this.value }, this.mode == "add" ? t("Email") : t(this.type)),
      h("div", null,
        h("smoothly-submit", { prevent: true, onSubmit: (e) => this.onSubmit(e) },
          h("smoothly-icon", { name: "checkmark-circle", toolTip: t("Save"), color: "success", fill: "clear", size: "small" })),
        h("smoothly-submit", { prevent: true, onSubmit: () => this.onCancel() },
          h("smoothly-icon", { name: "close-circle", toolTip: t("Cancel"), color: "light", fill: "clear", size: "small" })))));
  }
  static get is() { return "ig-email-input"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "value": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "value",
      "reflect": false
    },
    "types": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "EmailAddresses.Type[]",
        "resolved": "Type[]",
        "references": {
          "EmailAddresses": {
            "location": "import",
            "path": "@payfunc/model"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "defaultValue": "[]"
    },
    "type": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "\"primary\" | \"billing\"",
        "resolved": "\"billing\" | \"primary\"",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "type",
      "reflect": false,
      "defaultValue": "this.types[0]"
    },
    "mode": {
      "type": "string",
      "mutable": true,
      "complexType": {
        "original": "\"edit\" | \"add\"",
        "resolved": "\"add\" | \"edit\"",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "mode",
      "reflect": false,
      "defaultValue": "\"edit\""
    }
  }; }
  static get states() { return {
    "t": {}
  }; }
  static get events() { return [{
      "method": "edit",
      "name": "edit",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      }
    }, {
      "method": "add",
      "name": "add",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "{ type: string; value: string }",
        "resolved": "{ type: string; value: string; }",
        "references": {}
      }
    }, {
      "method": "notice",
      "name": "notice",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "Notice",
        "resolved": "Notice",
        "references": {
          "Notice": {
            "location": "import",
            "path": "smoothly"
          }
        }
      }
    }]; }
  static get elementRef() { return "element"; }
  static get listeners() { return [{
      "name": "selectionChanged",
      "method": "onSelectionChanged",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
