'use strict';

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

const index = require('./index-140bcbcd.js');
const unknown = require('./unknown-38d3748c.js');
const index$4 = require('./index-bddf9814.js');
const index$1 = require('./index-d3079b93.js');
const Token = require('./Token-8c5ba5d9.js');
require('./App-0b3e3f31.js');
const Notice = require('./Notice-e970b490.js');
const Trigger = require('./Trigger-a1c9ba71.js');
require('./Item-00ce8c24.js');
const index$5 = require('./index-ac98852d.js');
require('./Credentials-8e4749ab.js');
const index$2 = require('./index-b8543975.js');
const index$3 = require('./index-dc498c54.js');
const model = require('./model-38f84e2e.js');
require('./index-9d95c045.js');
const index$6 = require('./index-cc85865d.js');
require('./_commonjsHelpers-537d719a.js');
require('./index-09251373.js');
require('./TextDecoder-753156f3.js');
require('./index-f23d1d6b.js');

const styleCss$7 = ".sc-card-logotypes-h{display:-ms-flexbox;display:flex;width:100%;-ms-flex-pack:center;justify-content:center;margin:0.5em}[hidden].sc-card-logotypes-h{display:none}.sc-card-logotypes-h>svg.sc-card-logotypes{height:1.2em;margin:0.2em}";

const CardLogotypes = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
  }
  render() {
    return [
      index.h("svg", { xmlns: "http://www.w3.org/2000/svg", id: "svg8", version: "1.1", viewBox: "0 0 69.426948 28.154205" }, " ", index.h("path", { id: "path30", fill: "#1a1f71", d: "M 34.417564,4.5815956 30.343687,23.622847 h -4.925343 l 4.07416,-19.0412514 z m 20.724142,12.2947294 2.593058,-7.1501006 1.492391,7.1501006 z m 5.495431,6.746522 h 4.556478 L 61.217668,4.5815956 h -4.205676 c -0.944879,0 -1.742157,0.5497688 -2.09691,1.397 L 47.525093,23.622847 h 5.172287 l 1.027006,-2.843389 h 6.319802 z M 47.781916,17.406056 c 0.02117,-5.025814 -6.950288,-5.302674 -6.902028,-7.5477516 0.01439,-0.6835423 0.665763,-1.4094178 2.089009,-1.5954023 0.706967,-0.092287 2.650349,-0.1631244 4.857609,0.8523111 l 0.863882,-4.037471 c -1.185051,-0.4306711 -2.710462,-0.8444089 -4.60756,-0.8444089 -4.868332,0 -8.295357,2.5885422 -8.324426,6.2949667 -0.03048,2.740943 2.44602,4.270023 4.31292,5.181601 1.918546,0.933591 2.563425,1.531055 2.55524,2.365869 -0.0127,1.278466 -1.531055,1.841217 -2.946964,1.863795 -2.477347,0.03923 -3.914422,-0.668584 -5.060245,-1.202549 l -0.892386,4.172091 c 1.15062,0.528885 3.274624,0.98806 5.478497,1.011767 5.17398,0 8.559518,-2.556933 8.576452,-6.514818 M 27.378942,4.5815956 19.398544,23.622847 H 14.19098 L 10.263857,8.426591 C 10.02538,7.49046 9.8179463,7.1481244 9.0926353,6.75386 7.9098423,6.1115222 5.9543243,5.5086956 4.2333333,5.1347511 l 0.117969,-0.5531555 h 8.3811537 c 1.067929,0 2.029178,0.7109177 2.271324,1.9411244 l 2.074616,11.019367 5.12572,-12.9604914 z" })),
      index.h("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 131.39 86.9" }, index.h("rect", { opacity: "0", fill: "#fff", width: "131.39", height: "86.9" }), index.h("rect", { fill: "#ff5f00", x: "48.37", y: "15.14", width: "34.66", height: "56.61" }), index.h("path", { fill: "#eb001b", d: "M51.94,43.45a35.94,35.94,0,0,1,13.75-28.3,36,36,0,1,0,0,56.61A35.94,35.94,0,0,1,51.94,43.45Z" }), index.h("path", { fill: "#f79e1b", d: "M120.5,65.76V64.6H121v-.24h-1.19v.24h.47v1.16Zm2.31,0v-1.4h-.36l-.42,1-.42-1h-.36v1.4h.26V64.7l.39.91h.27l.39-.91v1.06Z" }), index.h("path", { fill: "#f79e1b", d: "M123.94,43.45a36,36,0,0,1-58.25,28.3,36,36,0,0,0,0-56.61,36,36,0,0,1,58.25,28.3Z" })),
    ];
  }
};
CardLogotypes.style = styleCss$7;

var VerificationError;
(function (VerificationError) {
  function is(value) {
    return (value &&
      value.status == 400 &&
      value.type == "malformed content" &&
      value.content &&
      value.content.description == "verification required" &&
      value.content.details &&
      (value.content.details.visible == undefined ||
        value.content.details.visible == true ||
        value.content.details.visible == false) &&
      typeof value.content.details.url == "string" &&
      ["GET", "POST"].includes(value.content.details.method) &&
      (value.content.details.data == undefined ||
        (typeof value.content.details.data == "object" &&
          Object.entries(value.content.details.data).every(v => typeof v[0] == "string" && typeof v[1] == "string"))));
  }
  VerificationError.is = is;
})(VerificationError || (VerificationError = {}));

const sv$2 = {
  "Card Number": "Kortnummer",
  Expires: "Giltigt till",
  Save: "Spara",
  Submit: "Skicka",
  Card: "Kort",
  "No response from payment server within time limit, please try again later.": "Inget respons från kortservrarna inom satt tidsbegränsning, var god försök igen senare.",
};

function create$2(language) {
  return index$1.dist.create({
    sv: sv$2,
  }, language);
}

const styleCss$6 = ".sc-ig-onboard-form-h{display:block}[hidden].sc-ig-onboard-form-h{display:none}.sc-ig-onboard-form-h>main.sc-ig-onboard-form{border:solid 2px rgb(var(--smoothly-primary-color))}.sc-ig-onboard-form-h>main.sc-ig-onboard-form>header.sc-ig-onboard-form{font-size:1.2em;padding:0.4em;display:-ms-flexbox;display:flex;background-color:rgb(var(--smoothly-primary-color));color:rgb(var(--smoothly-primary-contrast));font-family:var(--smoothly-font-family)}.sc-ig-onboard-form-h>main.sc-ig-onboard-form>header.sc-ig-onboard-form>smoothly-icon.sc-ig-onboard-form{width:1.1em;height:auto;margin-right:0.4em;fill:rgb(var(--smoothly-primary-contrast))}.sc-ig-onboard-form-h>smoothly-submit.sc-ig-onboard-form{margin-top:2rem;background-color:rgb(var(--smoothly-success-color));color:rgb(var(--smoothly-success-contrast));font-family:var(--smoothly-font-family)}";

const OnboardForm = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.notice = index.createEvent(this, "notice", 7);
    this.createCustomer = index.createEvent(this, "createCustomer", 7);
    this.processing = false;
  }
  async componentWillLoad() {
    var _a, _b, _c;
    this.t = create$2(this.hostElement);
    this.errorMessage = index$2.ErrorMessage.create("customer", (_a = index$1.dist.getLanguage(this.hostElement)) !== null && _a !== void 0 ? _a : "en");
    this.id = Token.Identifier.generate(16);
    this.client = await index$3.Client.open((_c = (_b = this.merchant) === null || _b === void 0 ? void 0 : _b.iss) !== null && _c !== void 0 ? _c : "", this.apiKey, "customer");
  }
  onUpdatedNotice(startProcessing) {
    if (this.responseTimer) {
      window.clearTimeout(this.responseTimer);
      this.responseTimer = undefined;
    }
    if (startProcessing) {
      this.responseTimer = window.setTimeout(() => {
        if (this.processing) {
          console.log("Max server response time reached.");
          this.notice.emit(Notice.Notice.failed(this.t("No response from payment server within time limit, please try again later.")));
          this.processing = false;
        }
        if (this.responseTimer) {
          window.clearTimeout(this.responseTimer);
          this.responseTimer = undefined;
        }
      }, 30000);
    }
  }
  TriggerListener(event) {
    if (Trigger.Trigger.is(event.detail) && (event.detail.name == "cardTokenFailed" || event.detail.name == "fail")) {
      if (VerificationError.is(event.detail.value)) {
        if (this.responseTimer) {
          window.clearTimeout(this.responseTimer);
          this.responseTimer = undefined;
        }
      }
      else {
        const message = this.errorMessage.generate(event);
        if (message && message != this.errorMessage.unknown)
          this.notice.emit(Notice.Notice.failed(message));
      }
    }
  }
  findInputFields(event) {
    const entries = Object.entries(event.detail);
    const email = entries.find(k => k[0].match(/email/gi));
    const phone = entries.find(k => k[0].match(/phone/gi));
    const name = entries.find(k => k[0].match(/name/gi));
    this.email = email && email[1] != "" ? email[1] : undefined;
    this.phone = phone && phone[1] != "" ? phone[1] : undefined;
    this.name = name && name[1] != "" ? name[1] : undefined;
  }
  async submit(event) {
    this.processing = true;
    this.findInputFields(event);
    const result = await this.submitHelper();
    this.processing = false;
    return result;
  }
  async submitHelper(error) {
    var _a, _b;
    let result;
    const card = await this.element.submit(this.card, error);
    let message;
    if (unknown.Error.is(card)) {
      message = this.errorMessage.generate(card);
      result = card;
    }
    else if (!card)
      result = undefined;
    else {
      this.card = card;
      let method;
      result = this.customer
        ? unknown.Error.is((method = await this.client.customer.createMethod({ card: this.card, type: "token", client: this.getClientData() }, ((_a = this.merchant) === null || _a === void 0 ? void 0 : _a.aud) == "customer" ? "me" : (_b = this.customer) === null || _b === void 0 ? void 0 : _b.id)))
          ? method
          : Object.assign(Object.assign({}, this.customer), { method: [...this.customer.method, method] })
        : await this.client.customer.create({
          id: this.id,
          number: this.number,
          method: [{ card: this.card, type: "token", client: this.getClientData() }],
          contact: {
            name: this.name,
            email: this.email,
            phone: this.phone,
          },
        });
      if (VerificationError.is(result))
        result = await this.submitHelper(result);
      else if (unknown.Error.is(result))
        message = this.errorMessage.generate(result);
      else if (!this.createCustomer.emit(result).defaultPrevented)
        this.paymentMethods = result;
    }
    if (unknown.Error.is(result) && message)
      this.notice.emit(Notice.Notice.failed(message));
    return result;
  }
  getClientData() {
    return {
      browser: {
        colorDepth: screen.colorDepth,
        resolution: [screen.width, screen.height],
        java: navigator.javaEnabled(),
        javascript: true,
        locale: index$4.dist.Locale.is(navigator.language) ? navigator.language : "en-GB",
        timezone: new Date().getTimezoneOffset(),
        parent: window.location.origin,
      },
    };
  }
  legacyOutput() {
    var _a;
    return ((_a = this.merchant) === null || _a === void 0 ? void 0 : _a.sub) ? ["BUeG1Dl0", "exZ-5a4T", "6lD8WwPl"].some(id => { var _a; return id == ((_a = this.merchant) === null || _a === void 0 ? void 0 : _a.sub); }) : false;
  }
  componentDidRender() {
    if (this.paymentMethods && this.submitElement) {
      this.submitElement.submit();
      this.processing = false;
    }
  }
  getCustomCssVariables() {
    var _a, _b, _c, _d;
    const cosmetic = typeof this.cosmetic == "string" ? JSON.parse(this.cosmetic) : this.cosmetic;
    const temp = {
      "--smoothly-primary-color": (_a = cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.header) === null || _a === void 0 ? void 0 : _a.background,
      "--smoothly-primary-contrast": (_b = cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.header) === null || _b === void 0 ? void 0 : _b.color,
      "--smoothly-success-color": (_c = cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.submit) === null || _c === void 0 ? void 0 : _c.background,
      "--smoothly-success-contrast": (_d = cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.submit) === null || _d === void 0 ? void 0 : _d.color,
      "--smoothly-font-family": cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.fontFamily,
      "--smoothly-danger-color": cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.dangerColor,
    };
    const result = {};
    Object.entries(temp).forEach(([key, value]) => {
      value && (result[key] = value);
    });
    return result;
  }
  render() {
    const t = this.t;
    return (index.h(index.Host, { style: this.getCustomCssVariables() }, index.h("main", null, index.h("header", null, index.h("smoothly-icon", { fill: "solid", name: "checkmark-circle" }), index.h("span", null, t("Card"))), index.h("intergiro-card-input", { cosmetic: this.cosmetic, apiKey: this.apiKey, ref: (element) => (this.element = element) })), index.h("smoothly-submit", { processing: this.processing, disabled: index$5.Customer.is(this.paymentMethods), color: "success", prevent: true, expand: "block", onSubmit: (event) => {
        this.submit(event);
        return false;
      }, ref: (element) => (this.submitElement = element) }, t("Submit")), this.paymentMethods ? (index.h("input", { type: "hidden", name: this.legacyOutput() ? "payment-methods" : "customer", value: JSON.stringify(this.paymentMethods) })) : ([])));
  }
  get hostElement() { return index.getElement(this); }
  static get watchers() { return {
    "processing": ["onUpdatedNotice"]
  }; }
};
OnboardForm.style = styleCss$6;

const styleCss$5 = ".sc-intergiro-card-input-h{display:block;height:var(--total-height);overflow:hidden;width:100%}[hidden].sc-intergiro-card-input-h{display:none}.sc-intergiro-card-input-h>smoothly-dialog.sc-intergiro-card-input{top:60px}.sc-intergiro-card-input-h>smoothly-dialog.sc-intergiro-card-input>*.sc-intergiro-card-input{border:none}";

const IntergiroCardInput = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.state = "created";
    this.layout = "standard";
  }
  async submit(input, error) {
    return this.element.submit(input, error);
  }
  render() {
    return (index.h("payfunc-card-input", { apiKey: this.apiKey, state: this.state, value: this.value, cosmetic: this.cosmetic, layout: this.layout, ref: (element) => (this.element = element) }));
  }
};
IntergiroCardInput.style = styleCss$5;

const en = {
  "By clicking the $0 button I accept the terms and conditions ($1).": (buttonName, url) => [
    "By clicking the " + buttonName + " button I accept the ",
    index.h("a", { href: url }, "terms and conditions"),
    ".",
  ],
};

const sv$1 = {
  "By clicking the $0 button I accept the terms and conditions ($1).": (buttonName, url) => [
    "Genom att klicka på " + buttonName + "-knappen godkänner jag ",
    index.h("a", { href: url }, "villkoren"),
    ".",
  ],
};

function create$1(language) {
  return index$1.dist.create({
    sv: sv$1,
    en,
  }, language);
}

const styleCss$4 = ".sc-merchant-terms-h{display:block}[hidden].sc-merchant-terms-h{display:none}.sc-merchant-terms-h>p.sc-merchant-terms{font-size:smaller;text-align:center}";

const MerchantTerms = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
  }
  componentWillLoad() {
    this.t = create$1(this.element);
  }
  render() {
    const t = this.t;
    return [
      index.h("p", null, !this.merchant
        ? ""
        : this.merchant.terms
          ? t("By clicking the $0 button I accept the terms and conditions ($1).", this.buttonName, this.merchant.terms)
          : ""),
    ];
  }
  get element() { return index.getElement(this); }
};
MerchantTerms.style = styleCss$4;

async function from(error, merchant, value) {
  var _a, _b, _c;
  return {
    show: error.content.details.visible,
    url: !error.content.details.data || error.content.details.method == "GET"
      ? error.content.details.url
      : await getIframeUrl((_b = (_a = merchant.card) === null || _a === void 0 ? void 0 : _a.url) !== null && _b !== void 0 ? _b : "", error.content.details.url, error.content.details.data, merchant, value),
    data: (_c = error.content.details.data) !== null && _c !== void 0 ? _c : {},
  };
}
async function getIframeUrl(issuer, url, data, merchant, value) {
  var _a, _b, _c, _d, _e, _f, _g, _h;
  let card;
  if (Token.Token.is(value))
    card = (_b = (_a = (await index$6.Card.V1.Token.verify(value))) === null || _a === void 0 ? void 0 : _a.card) !== null && _b !== void 0 ? _b : (await index$6.Card.Token.verify(value));
  const version = ["2.1.0", "2.2.0"].includes(data.messageVersion)
    ? data.messageVersion
    : undefined;
  const callback = index$6.Card.Token.is(card) && issuer
    ? index$6.Card.Token.getVerificationTarget(card, issuer, encodeURIComponent(window.location.origin), version)
    : `${issuer + (!issuer.endsWith("/") ? "/" : "")}card/${card}/verification?mode=iframe&merchant=${(_e = (_d = (_c = merchant === null || merchant === void 0 ? void 0 : merchant.card) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : merchant === null || merchant === void 0 ? void 0 : merchant.sub) !== null && _e !== void 0 ? _e : "error"}&parent=${encodeURIComponent(window.location.origin)}${version ? `&v=${version}` : ""}`;
  data = (_h = (_g = (_f = ch3d1Data(data, callback, value)) !== null && _f !== void 0 ? _f : ch3d2MethodData(data, callback)) !== null && _g !== void 0 ? _g : ch3d2ChallengeData(data)) !== null && _h !== void 0 ? _h : data;
  const result = typeof data == "object" && Object.entries(data).length > 0
    ? Object.entries(data).reduce((a, b) => a + "&" + encodeURIComponent(b[0]) + "=" + encodeURIComponent(b[1]), "")
    : "";
  return "https://api.payfunc.com/redirect/post?target=" + encodeURIComponent(url) + result;
}
function ch3d1Data(data, callback, value) {
  let result;
  if (data.PaReq || data.pareq) {
    result = Object.assign({}, data);
    if (result.pareq) {
      result.PaReq = result.pareq;
      delete result.pareq;
    }
    if (!result.TermUrl)
      result.TermUrl = callback;
    if (!result.MD)
      result.MD = value !== null && value !== void 0 ? value : "error";
  }
  return result;
}
function ch3d2MethodData(data, callback) {
  let result;
  if (data.type == "method" && data.threeDSServerTransID)
    result = {
      threeDSMethodData: Token.encode(JSON.stringify({
        threeDSServerTransID: data.threeDSServerTransID,
        threeDSMethodNotificationURL: callback,
      }), "url"),
    };
  return result;
}
function ch3d2ChallengeData(data) {
  let result;
  if (data.type == "challenge" && data.threeDSServerTransID)
    result = {
      creq: Token.encode(JSON.stringify({
        threeDSServerTransID: data.threeDSServerTransID,
        acsTransID: data.acsTransID,
        messageVersion: data.messageVersion,
        messageType: data.messageType,
        challengeWindowSize: data.challengeWindowSize,
      }), "url"),
    };
  return result;
}

const styleCss$3 = ".sc-payfunc-card-input-h{display:block;height:var(--total-height);overflow:hidden;width:100%}[hidden].sc-payfunc-card-input-h{display:none}.sc-payfunc-card-input-h>smoothly-dialog.sc-payfunc-card-input{top:60px}.sc-payfunc-card-input-h>smoothly-dialog.sc-payfunc-card-input>*.sc-payfunc-card-input{border:none}";

const PayfuncCardInput = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.state = "created";
    this.layout = "standard";
  }
  async componentWillLoad() {
    this.merchant = await model.MerchantKeyUnpack(this.apiKey);
    const styleLink = document.querySelector("link[rel=stylesheet][href^='https://theme.payfunc.com/']");
    if (styleLink) {
      const themeLink = styleLink.href.substring(26);
      this.theme = themeLink.substring(0, themeLink.indexOf("/"));
    }
  }
  verifyTimer() {
    let data;
    if (!this.verify) {
      window.clearTimeout(this.responseTimer);
      this.responseTimer = undefined;
    }
    else if (this.verify && this.verify.show === false && this.verify.data)
      this.responseTimer = window.setTimeout(() => {
        var _a, _b;
        if ((_b = (data = (_a = this.verify) === null || _a === void 0 ? void 0 : _a.data)) === null || _b === void 0 ? void 0 : _b.threeDSServerTransID) {
          console.log("Method call max server response time reached.");
          window.clearTimeout(this.responseTimer);
          this.responseTimer = undefined;
          this.frame.send("card", {
            name: "methodTimeout",
            value: {
              card: this.value,
              key: this.apiKey,
              parent: window.location.origin,
              verificationId: data.threeDSServerTransID,
              version: ["2.1.0", "2.2.0"].includes(data.messageVersion) ? data.messageVersion : undefined,
            },
          });
        }
      }, 15000);
  }
  async handleTrigger(event) {
    if (!VerificationError.is(event.detail.value)) {
      this.verify = undefined;
      if (Token.Token.is(event.detail.value))
        this.value = event.detail.value;
      this.state = event.detail.name == "cardTokenSuccess" ? "succeeded" : "failed";
      if (this.received) {
        this.received(this.state, event.detail.value);
        this.received = undefined;
      }
    }
  }
  async submit(input, error) {
    if (Token.Token.is(input))
      this.value = input;
    if (VerificationError.is(error) && this.merchant && this.value)
      this.verify = await from(error, this.merchant, this.value);
    return new Promise(callback => {
      if (this.frame) {
        this.received = (_, response) => callback(response);
        const value = { card: this.value, key: this.apiKey, parent: window.location.origin };
        this.frame.send("card", !error ? { name: "submit", value } : { name: "cardCheck", value: Object.assign(Object.assign({}, value), { error }) });
        this.state = "processing";
      }
    });
  }
  getCustomCssVariables() {
    var _a, _b, _c, _d;
    const cosmetic = typeof this.cosmetic == "string" ? JSON.parse(this.cosmetic) : (_a = this.cosmetic) !== null && _a !== void 0 ? _a : {};
    const result = {};
    let rows, borders, gaps;
    if (this.layout == "row") {
      rows = "1";
      borders = cosmetic.gap ? "2" : "0";
      gaps = "0";
    }
    else if (this.layout == "column") {
      rows = "3";
      borders = cosmetic.gap ? "6" : "2";
      gaps = "2";
    }
    else {
      rows = "2";
      borders = cosmetic.gap ? "4" : "1";
      gaps = "1";
    }
    const borderHeight = (_c = (_b = cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.border) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : "1px";
    const gapHeight = (_d = cosmetic === null || cosmetic === void 0 ? void 0 : cosmetic.gap) !== null && _d !== void 0 ? _d : "0em";
    result["--total-height"] = `calc(41px * ${rows} + ${borderHeight} * ${borders} + ${gapHeight} * ${gaps})`;
    return result;
  }
  render() {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
    const parameters = [];
    this.theme && parameters.push({ key: "theme", value: this.theme });
    this.cosmetic &&
      parameters.push({
        key: "cosmetic",
        value: encodeURIComponent(typeof this.cosmetic == "string" ? this.cosmetic : JSON.stringify(this.cosmetic)),
      });
    this.layout && parameters.push({ key: "layout", value: this.layout });
    const parametersString = parameters.length > 0 ? "?" + parameters.map(param => `${param.key}=${param.value}`).join("&") : "";
    return (index.h(index.Host, { style: this.getCustomCssVariables() }, this.merchant ? (index.h("smoothly-frame", { url: ((_b = (_a = this.merchant) === null || _a === void 0 ? void 0 : _a.card) === null || _b === void 0 ? void 0 : _b.url) + "/ui/card-tokenizer/" + parametersString, origin: ((_d = (_c = this.merchant) === null || _c === void 0 ? void 0 : _c.card) === null || _d === void 0 ? void 0 : _d.url) ? new URL((_f = (_e = this.merchant) === null || _e === void 0 ? void 0 : _e.card) === null || _f === void 0 ? void 0 : _f.url).origin : undefined, name: "card", ref: (element) => (this.frame = element) })) : ([]), this.verify ? (this.verify.show ? (index.h("smoothly-dialog", { color: "default", closable: true }, index.h("smoothly-frame", { url: this.verify.url, origin: ((_h = (_g = this.merchant) === null || _g === void 0 ? void 0 : _g.card) === null || _h === void 0 ? void 0 : _h.url) ? new URL((_k = (_j = this.merchant) === null || _j === void 0 ? void 0 : _j.card) === null || _k === void 0 ? void 0 : _k.url).origin : undefined, name: "parent", style: { height: "90vh" } }))) : (index.h("smoothly-frame", { hidden: true, url: this.verify.url, origin: ((_m = (_l = this.merchant) === null || _l === void 0 ? void 0 : _l.card) === null || _m === void 0 ? void 0 : _m.url) ? new URL((_p = (_o = this.merchant) === null || _o === void 0 ? void 0 : _o.card) === null || _p === void 0 ? void 0 : _p.url).origin : undefined, name: "parent", style: { height: "90vh" } }))) : ([])));
  }
  static get watchers() { return {
    "verify": ["verifyTimer"]
  }; }
};
PayfuncCardInput.style = styleCss$3;

const sv = {
  Submit: "Skicka",
  "No valid API key.": "Ingen giltig API-nyckel.",
};

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

const styleCss$2 = ".sc-payfunc-onboard-h{display:block;max-width:40em}";

const Onboard = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.create = index.createEvent(this, "create", 7);
  }
  async componentWillLoad() {
    var _a;
    this.merchant = await index$5.Key.unpack(this.apiKey, "public", "customer", "private");
    this.t = create(this.element);
    this.customerNumber = (_a = this.number) !== null && _a !== void 0 ? _a : Token.Identifier.generate(16);
  }
  onCreate(event) {
    this.create.emit(event.detail);
  }
  render() {
    const t = this.t;
    return !this.merchant ? (index.h("p", null, this.t("No valid API key."))) : ([
      index.h("smoothly-notifier", null, index.h("ig-onboard-form", { cosmetic: this.cosmetic, merchant: this.merchant, customer: this.customer, "api-key": this.apiKey, number: this.customerNumber, "response-timer": this.responseTimer }), index.h("merchant-terms", { merchant: this.merchant, buttonName: t("Submit") }), index.h("card-logotypes", null)),
    ]);
  }
  get element() { return index.getElement(this); }
};
Onboard.style = styleCss$2;

const styleCss$1 = ".sc-smoothly-notification-h{display:block;min-width:32.6%;min-height:3em;border-radius:5px;margin:0.5em}[hidden].sc-smoothly-notification-h{display:none}smoothly-trigger.sc-smoothly-notification{float:right;text-align:right;margin-right:0.2em}";

const Notification = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.remove = index.createEvent(this, "remove", 7);
    this.tick = {};
    this.listener = notice => {
      console.log("changed: ", notice);
      if (notice.state == "closed")
        this.remove.emit(notice);
      else
        this.tick = {};
    };
  }
  get color() {
    let result;
    switch (this.notice.state) {
      case "delayed":
      case "warning":
        result = "warning";
        break;
      case "success":
        result = "success";
        break;
      case "executing":
        result = "light";
        break;
      case "failed":
        result = "danger";
        break;
      default:
        result = "light";
        break;
    }
    return result;
  }
  onTrigger(event) {
    if (event.detail.name == "close") {
      event.stopPropagation();
      this.notice.close();
    }
  }
  onUpdatedNotice(newValue, oldValue) {
    if (oldValue)
      oldValue.unlisten(this.listener);
    newValue.listen(this.listener);
  }
  componentDidLoad() {
    this.onUpdatedNotice(this.notice);
  }
  render() {
    return (index.h(index.Host, { color: this.color, fill: "solid" }, index.h("smoothly-trigger", { fill: "clear", name: "close" }, index.h("smoothly-icon", { name: "close-circle-outline" })), index.h("p", null, this.notice.message)));
  }
  static get watchers() { return {
    "notice": ["onUpdatedNotice"]
  }; }
};
Notification.style = styleCss$1;

const styleCss = ".sc-smoothly-notifier-h{display:block}[hidden].sc-smoothly-notifier-h{display:none}.sc-smoothly-notifier-h>aside.sc-smoothly-notifier{display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap-reverse;flex-wrap:wrap-reverse;-ms-flex-line-pack:stretch;align-content:stretch;-ms-flex-pack:start;justify-content:flex-start;position:fixed;bottom:3em;left:0;text-align:center;width:100%;z-index:3}";

const Notifier = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.notices = [];
  }
  onNotice(event) {
    this.notices = [...this.notices, event.detail];
  }
  onRemove(event) {
    this.notices = [...this.notices.filter(n => n != event.detail)];
  }
  render() {
    return [
      index.h("slot", null),
      index.h("aside", null, this.notices.map(n => (index.h("smoothly-notification", { notice: n })))),
    ];
  }
};
Notifier.style = styleCss;

exports.card_logotypes = CardLogotypes;
exports.ig_onboard_form = OnboardForm;
exports.intergiro_card_input = IntergiroCardInput;
exports.merchant_terms = MerchantTerms;
exports.payfunc_card_input = PayfuncCardInput;
exports.payfunc_onboard = Onboard;
exports.smoothly_notification = Notification;
exports.smoothly_notifier = Notifier;
