'use strict';

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

const index = require('./index-ee190ee0.js');
const store = require('./store-5a3b44dc.js');
require('./index-4901314f.js');
require('./getHandlebarsHelpers-8ef28401.js');
require('./_commonjsHelpers-a5111d61.js');
require('./index-ba857994.js');
require('./localforage-af1b8c0e.js');

const inputAmountCss = "fireenjin-input .invalid{--border-color:var(--ion-color-danger) !important}fireenjin-input .invalid ion-label{color:var(--ion-color-danger) !important}fireenjin-input .valid{--border-color:var(--ion-color-success) !important}fireenjin-input .valid ion-label{color:var(--ion-color-success) !important}fireenjin-input ion-label{font-size:16px !important;font-weight:bold !important;display:block;background:transparent;text-align:left;padding:0 0 8px 0;font-family:var(--ion-font-family)}fireenjin-input-amount ion-item ion-input{color:var(--ion-text-color);border:none;box-shadow:none !important;font-family:var(--ion-font-family);outline:none !important;--padding-top:5px !important;--padding-bottom:3px !important;--padding-start:8px}fireenjin-input-amount ion-item ion-input input.native-input{font-size:18px !important;font-weight:bold !important;text-indent:15px !important}fireenjin-input-amount ion-item.item-has-focus{--border-width:0 0 2px 0;--border-color:var(--ion-color-primary)}fireenjin-input-amount ion-item.item-has-focus ion-label{color:var(--ion-color-primary) !important}fireenjin-input-amount ion-item ion-icon[slot=\"start\"]{position:absolute;top:25px;left:8px;color:var(--ion-color-medium-shade)}fireenjin-input-amount ion-item .input-clear-icon{display:none !important;visibility:hidden !important}fireenjin-input-amount ion-item .text-input-clear-icon{display:none !important}fireenjin-input-amount .presets{position:absolute;top:6px;right:0px;-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}fireenjin-input-amount .presets span{border:1px solid var(--ion-text-color);color:var(--ion-text-color);padding:3px 8px;margin-left:13px;font-size:12px;font-weight:bold;transition:300ms ease all;border-radius:3px}fireenjin-input-amount .presets span:hover{cursor:pointer;color:var(--ion-color-success);border-color:var(--ion-color-success)}fireenjin-input-amount .presets span.selected{background-color:var(--ion-color-success);color:#ffffff;border:none}fireenjin-input-amount .hidden-input{display:block;visibility:hidden;height:0;opacity:0}fireenjin-input-amount ion-input{font-weight:bold;font-size:20px}fireenjin-input-amount input::-webkit-outer-spin-button,fireenjin-input-amount input::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}fireenjin-input-amount input[type=\"number\"]{-moz-appearance:textfield}";

const InputAmount = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.ionInput = index.createEvent(this, "ionInput", 7);
    this.ionChange = index.createEvent(this, "ionChange", 7);
    this.name = undefined;
    this.label = undefined;
    this.placeholder = undefined;
    this.value = undefined;
    this.required = false;
    this.presets = undefined;
    this.decimal = undefined;
    this.autofocus = undefined;
    this.disabled = undefined;
    this.min = undefined;
    this.max = undefined;
    this.step = "0.01";
    this.lines = undefined;
    this.labelPosition = undefined;
    this.formattedValue = undefined;
  }
  onChange(event) {
    this.formattedValue = this.formatCurrency(event.target.value);
  }
  onValueChange(newValue, oldValue) {
    if (newValue === oldValue)
      return false;
    this.formattedValue = this.formatCurrency(this.value);
  }
  formatCurrency(amount) {
    if (!amount || isNaN(parseFloat(amount))) {
      this.value = null;
      this.inputEl.value = null;
      return null;
    }
    const formattedAmount = Number(parseFloat((amount + "").replace(",", "")).toFixed(2));
    const formatter = new Intl.NumberFormat("en-US", {
      style: "currency",
      currency: "USD",
      minimumFractionDigits: 2,
    });
    document.querySelectorAll(".presets span").forEach((span) => {
      if (+formattedAmount ===
        +parseFloat((span.textContent + "")
          .replace(",", "")
          .replace("$", "")
          .replace(" ", "")).toFixed(2)) {
        span.classList.add("selected");
      }
      else {
        span.classList.remove("selected");
      }
    });
    this.value = formattedAmount;
    setTimeout(() => {
      this.ionInput.emit({
        name: this.name,
        value: formattedAmount,
      });
      this.ionChange.emit({
        name: this.name,
        value: formattedAmount,
      });
    }, 200);
    return formatter.format(formattedAmount).replace("$", "");
  }
  componentDidLoad() {
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser))
      return;
    this.formattedValue = this.formatCurrency(this.value);
  }
  selectPreset(preset) {
    this.formattedValue = this.formatCurrency(typeof preset === "string" ? preset : (preset === null || preset === void 0 ? void 0 : preset.value) ? preset.value : 0);
  }
  render() {
    return (index.h("ion-item", { lines: this.lines }, index.h("ion-icon", { name: "logo-usd", slot: "start" }), this.label && (index.h("ion-label", { position: this.labelPosition }, this.label)), this.presets && this.presets.length && (index.h("div", { class: "presets", slot: "end" }, this.presets.map((preset) => (index.h("span", { onClick: () => this.selectPreset(preset) }, typeof preset === "string"
      ? preset
      : (preset === null || preset === void 0 ? void 0 : preset.label)
        ? preset.label
        : (preset === null || preset === void 0 ? void 0 : preset.value)
          ? preset.value
          : ""))))), index.h("ion-input", { min: this.min, max: this.max, ref: (el) => (this.inputEl = el), disabled: this.disabled, inputmode: "decimal", type: "tel", step: this.step, placeholder: this.placeholder, required: this.required, autofocus: this.autofocus, value: this.formattedValue })));
  }
  static get watchers() { return {
    "value": ["onValueChange"]
  }; }
};
InputAmount.style = inputAmountCss;

const payCardCss = "floodteam-pay-card{display:block;width:100%;font-family:var(--ion-font-family, Arial, Helvetica, sans-serif)}floodteam-pay-card .pay-card-wrapper{width:90%;max-width:600px;margin:15px auto}floodteam-pay-card .pay-card-wrapper .StripeElement--webkit-autofill{background-color:#fefde5 !important}floodteam-pay-card .pay-card-wrapper ion-grid{display:block;width:100%;padding:15px 0 0 0}";

const PayCard = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.ftSubmitCard = index.createEvent(this, "ftSubmitCard", 7);
    this.ionChange = index.createEvent(this, "ionChange", 7);
    this.fireenjinError = index.createEvent(this, "fireenjinError", 7);
    this.ftCardError = index.createEvent(this, "ftCardError", 7);
    this.ftCancel = index.createEvent(this, "ftCancel", 7);
    var _a, _b, _c, _d, _e, _f;
    this.stripeStyle = {
      base: {
        color: (store.state === null || store.state === void 0 ? void 0 : store.state.darkMode) ? "#FFFFFF" : "#000000",
        iconSize: "30px",
        iconColor: "#999999",
        lineHeight: "20px",
        fontFamily: '"Work Sans", sans-serif',
        fontSmoothing: "antialiased",
        fontSize: "18px",
        "::placeholder": {
          color: "#999999",
          iconColor: "#999999",
          fontWeight: "normal",
        },
      },
      invalid: {
        color: "#ee6274",
        iconColor: "#ee6274",
      },
    };
    this.stripeKey = ((_a = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _a === void 0 ? void 0 : _a.isFranchise) && ((_d = (_c = (_b = store.state.config) === null || _b === void 0 ? void 0 : _b.franchise) === null || _c === void 0 ? void 0 : _c.stripe) === null || _d === void 0 ? void 0 : _d.key)
      ? store.state.config.franchise.stripe.key
      : (_f = (_e = store.state.config) === null || _e === void 0 ? void 0 : _e.stripe) === null || _f === void 0 ? void 0 : _f.key;
    this.tokenOnComplete = false;
    this.name = "token";
    this.value = undefined;
    this.card = undefined;
    this.error = undefined;
    this.isLoading = false;
  }
  async onChange({ target, detail: { event: { complete, error }, }, }) {
    if (error)
      this.fireenjinError.emit({
        name: "payCard",
        error: {
          response: {
            errors: [error],
          },
        },
      });
    if (!this.tokenOnComplete || !complete)
      return;
    const { token } = await this.getCardToken();
    this.value = token;
    this.ionChange.emit({
      name: this.name,
      value: this.value,
    });
    if (target.closest("fireenjin-flow"))
      target.closest("fireenjin-flow").slideNext();
  }
  async getCardToken() {
    this.error = null;
    this.isLoading = true;
    try {
      const res = await this.cardInputEl.getCardToken(this.card);
      this.isLoading = false;
      return res;
    }
    catch (e) {
      this.error = (e === null || e === void 0 ? void 0 : e.message) || null;
      this.isLoading = false;
      console.log(e);
      return false;
    }
  }
  render() {
    console.log(store.state === null || store.state === void 0 ? void 0 : store.state.job, this.stripeKey);
    return (index.h("div", { class: this.isLoading ? "pay-card-wrapper is-loading" : "pay-card-wrapper" }, this.error ? index.h("floodteam-error", { message: this.error }) : null, index.h("fireenjin-input", { ref: (el) => (this.cardInputEl = el), lines: "none", stripeKey: this.stripeKey, stripeElements: {
        style: {
          base: {
            color: (store.state === null || store.state === void 0 ? void 0 : store.state.darkMode) ? "#ffffff" : "#000000",
            lineHeight: "18px",
            fontFamily: "PT Sans, Helvetica, sans-serif",
            fontSmoothing: "antialiased",
            fontSize: "16px",
            fontWeight: "bold",
            "::placeholder": {
              color: "#bebebe",
            },
            left: "15px",
          },
          invalid: {
            color: "#db3a5e",
            iconColor: "#db3a5e",
          },
        },
        iconStyle: "solid",
        placeholder: "Card Number",
      }, type: "card", name: "card" })));
  }
  get payCardEl() { return index.getElement(this); }
};
PayCard.style = payCardCss;

/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0

THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.

See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */

function __awaiter(thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
}

class HttpService {
    constructor(options = {}) {
        this.shouldBeAsync = true;
        this.host = options.host;
        this.headers = options.headers ? options.headers : {};
    }
    serializeParams(data) {
        return Object.keys(data)
            .map(key => `${key}=${encodeURIComponent(data[key])}`)
            .join("&");
    }
    makePromise(method, endpoint, params) {
        return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
            const request = new XMLHttpRequest();
            request.open(method, `${this.host}/${endpoint}${method === "GET" ? "?" + this.serializeParams(params) : ""}`, this.shouldBeAsync);
            request.onload = (res) => __awaiter(this, void 0, void 0, function* () {
                const data = JSON.parse(request.responseText);
                if (data && request.status === 200) {
                    resolve({ data });
                }
                else {
                    reject(Object.assign({}, data, { message: data.error }));
                }
            });
            request.onerror = req => {
                reject({
                    message: "There was an error talking to the API, please try agian later or contact support!",
                    status: request.status
                });
            };
            Object.keys(this.headers).map(key => {
                request.setRequestHeader(key, this.headers[key]);
            });
            request.send(method === "DELETE" || method === "GET"
                ? null
                : params
                    ? JSON.stringify(params)
                    : "{}");
        }));
    }
    delete(endpoint, params) {
        return this.makePromise("DELETE", endpoint, params);
    }
    get(endpoint, params) {
        return this.makePromise("GET", endpoint, params);
    }
    post(endpoint, params) {
        return this.makePromise("POST", endpoint, params);
    }
    put(endpoint, params) {
        return this.makePromise("PUT", endpoint, params);
    }
}

class DadeMobile {
    constructor(apiKey, apiBaseUrl) {
        this.http = new HttpService({
            host: apiBaseUrl,
            headers: {
                Accept: "application/json",
                Authorization: `Token ${apiKey}`,
                "Content-Type": "application/json",
                "X-DADEMC": true
            }
        });
    }
    pick(obj, whitelist) {
        return Object.assign({}, ...whitelist.map(key => ({ [key]: obj[key] })));
    }
    pickPaymentData(data) {
        const payment = this.pick(data, [
            "id",
            "type",
            "status",
            "amount",
            "external_user_id",
            "external_reference",
            "date"
        ]);
        payment.amount = data.check_amount;
        return payment;
    }
    pickCheckData(data) {
        return this.pick(data, [
            "check_routing_number",
            "check_account_number",
            "check_number"
        ]);
    }
    /**
     * After initialization, the next step is to stage a payment.
     * The payment amount can be set when staging a payment, or after a payment has already been staged, depending on your workflow.
     * If a payment was previously staged but not confirmed, then it will be resumed.
     */
    stagePayment(params) {
        return new Promise((resolve, reject) => {
            this.http
                .get("mobile_payments/new", Object.assign({}, params, { check_amount: params["amount"] }))
                .then(payload => {
                const payment = this.pickPaymentData(payload.data);
                resolve(payment);
            })
                .catch(error => {
                reject(error);
            });
        });
    }
    /**
     * Set the amount of a staged payment.
     */
    setAmount(
    /**
     * The staged payment.
     */
    payment, 
    /**
     * Payment amount.
     */
    amount) {
        return new Promise((resolve, reject) => {
            this.http
                .put(`mobile_payments/${payment.id}`, {
                mobile_payment: {
                    check_amount: amount
                }
            })
                .then(payload => {
                const mobile_payment = this.pickPaymentData(payload.data);
                resolve(Object.assign({}, payment, mobile_payment));
            })
                .catch(error => {
                reject(error);
            });
        });
    }
    /**
     * Upload image for a staged payment.
     */
    uploadImage(
    /**
     * The staged payment.
     */
    payment, 
    /**
     * The type of image being uploaded
     */
    imageType, 
    /**
     * Base64 encoding of the image data.
     */
    imageString) {
        return new Promise((resolve, reject) => {
            this._resizeImage(imageString).then(resizedImage => {
                this.http
                    .post(`mobile_payments/${payment.id}/mobile_checks`, {
                    image_type: imageType,
                    image_string: resizedImage
                })
                    .then(_payload => {
                    resolve(Object.assign({}, payment, { [imageType]: true }));
                })
                    .catch(error => {
                    reject(error);
                });
            });
        });
    }
    /**
     * Once a payment is staged and all properties have been set, the final step is to confirm the payment.
     * If the payment fails validation, then validation errors will be returned. See the next section for error codes.
     */
    confirmPayment(
    /**
     * The staged payment.
     */
    payment, params) {
        return new Promise((resolve, reject) => {
            this.http
                .post(`mobile_payments/${payment.id}/mobile_confirmation`, params)
                .then(payload => {
                const confirmation = payload.data;
                const mobile_payment = this.pickPaymentData(confirmation.mobile_payment);
                const check_data = this.pickCheckData(confirmation);
                resolve(Object.assign({}, mobile_payment, check_data));
            })
                .catch(error => {
                try {
                    reject({
                        validationErrors: error.response.data.errors
                    });
                }
                catch (_a) {
                    reject(error);
                }
            });
        });
    }
    /**
     * Cancel a scanned payment
     */
    cancelPayment(
    /**
     * The staged payment.
     */
    payment) {
        return new Promise((resolve, reject) => {
            this.http
                .delete(`mobile_payments/${payment.id}`)
                .then(_payload => {
                resolve(true);
            })
                .catch(error => {
                reject(error);
            });
        });
    }
    _resizeImage(imageData) {
        const MAX_WIDTH = 1200;
        const MAX_HEIGHT = 1200;
        const tempImage = new Image();
        const imageDataUrl = `data:image/jpeg;base64,${imageData}`;
        return new Promise((resolve, _reject) => {
            tempImage.src = imageDataUrl;
            tempImage.onload = function () {
                let width = tempImage.width;
                let height = tempImage.height;
                if (width > height) {
                    if (width > MAX_WIDTH) {
                        height *= MAX_WIDTH / width;
                        width = MAX_WIDTH;
                    }
                }
                else {
                    if (height > MAX_HEIGHT) {
                        width *= MAX_HEIGHT / height;
                        height = MAX_HEIGHT;
                    }
                }
                const canvas = document.createElement("canvas");
                canvas.width = width;
                canvas.height = height;
                const ctx = canvas.getContext("2d");
                ctx.drawImage(tempImage, 0, 0, width, height);
                const dataURL = canvas.toDataURL("image/jpeg");
                const imageBase64 = dataURL.split(",")[1];
                resolve(imageBase64);
            };
        });
    }
}

const payCheckCss = "floodteam-pay-check{font-family:var(\n    --floodteam-pay-check-font-family,\n    var(--ion-font-family, Arial, Helvetica, sans-serif)\n  );display:block;width:100%}floodteam-pay-check floodteam-flip-card [slot=\"after\"] img{opacity:0;pointer-events:none}floodteam-pay-check #form-check floodteam-button.flip{position:absolute;right:15px}floodteam-pay-check #form-check form{margin:0 auto;width:90%}floodteam-pay-check #form-check input[type=\"file\"]{height:0;width:0;visibility:hidden;opacity:0}floodteam-pay-check #form-check img{display:block;width:100%}floodteam-pay-check #form-check fireenjin-input{--fireenjin-input-font-size:1.5em;--fireenjin-input-width:160px;--fireenjin-input-focus-color:#0f78b9;--fireenjin-input-margin:0 0 0 0;--fireenjin-input-label-top:10px;--floodteam-icon-bottom:8px}floodteam-pay-check floodteam-flip-card{cursor:pointer}floodteam-pay-check floodteam-flip-card .flip-card{height:150px !important}floodteam-pay-check #form-check floodteam-flip-card.check-drag-hover .flip-card-front,floodteam-pay-check #form-check floodteam-flip-card.check-drag-hover .flip-card-back{background-image:url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlgAAAD6CAMAAABK88kiAAAAA3NCSVQICAjb4U/gAAAAe1BMVEWJiYm7u7u/v7+RkZH7+/upqanZ2dmdnZ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XVrSO1S/5diXdZJIEcRwHiaRviV9Yw5n6Rc6LUNCGIwrVtzQXtRJmGNZ2rn7Rt6S5IvOte07W1p1hWIfzDV+2n4c55VtF2oEuu7CycCHrsNBP1V5j3Gpa1R5jF1a+q7tYLAR9CM+dq1XwfCtor1HhF1bmekHginl/T7xihSVpp7HAL6xhliSJmM9K+Wt1SDiYC/tUIcuwhoKuf/iho7parKWtsFiGJcckLboaBMJ+p9wQYdnku16xHRysxG0IEZY9WbKej4qu5jNxG0IJYfn+1+S77PtBYxT5PVsocoPFoatQzKFIBfuwvsLgghd+22dRs270bKEvzym7Ws0kdsU+LD9cxaML8/qvcfI3gXO5lN2FkkBdQRgtBJ2Sq+Ee1uT4xq+Jg031h5gffPVuocSbx3E8T+UdD5a4h+U3+kk3qu+xC/nqAkLqtptDjgHuYUVbz3F6tpVrtNAwmySJ2Kz4h5Uftc8u9pQ57LxLxz6sfKXV5Pj/chnrC8kmICzoI4QFJBAWkEBYQAJhAQmEBSQQFpBAWEACYQEJhAUkEBaQQFhAAmEBCYQFJBAWkEBYQAJhAQmEBSQQFpBAWEACYQEJhAUkEBaQQFhAAmEBCYQFJBAWkEBYQAJhAQmEBSQQFpBAWEACYQEJhAUkEBaQQFhAAmEBCYQFJBAWkPgffnBX30Xd5dgAAAAASUVORK5CYII=\") !important}floodteam-pay-check #form-check .top-bar .right floodteam-button{float:right}floodteam-pay-check #form-check .bottom-bar{margin-top:20px}floodteam-pay-check #form-check floodteam-grid{padding-top:15px}floodteam-pay-check .check-scanner-preview{cursor:pointer}";

const PayCheck = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.ftSubmitCheck = index.createEvent(this, "ftSubmitCheck", 7);
    this.ftCheckConfirmation = index.createEvent(this, "ftCheckConfirmation", 7);
    this.ftCheckScan = index.createEvent(this, "ftCheckScan", 7);
    this.ftCheckError = index.createEvent(this, "ftCheckError", 7);
    this.ftCancel = index.createEvent(this, "ftCancel", 7);
    var _a, _b, _c, _d, _e, _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/chnrC8kmICzoI4QFJBAWkEBYQAJhAQmEBSQQFpBAWEACYQEJhAUkEBaQQFhAAmEBCYQFJBAWkEBYQAJhAQmEBSQQFpBAWEACYQEJhAUkEBaQQFhAAmEBCYQFJBAWkEBYQAJhAQmEBSQQFpBAWEACYQEJhAUkEBaQQFhAAmEBCYQFJBAWkPgffnBX30Xd5dgAAAAASUVORK5CYII=";
    this.apiKey = ((_a = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _a === void 0 ? void 0 : _a.isFranchise) && ((_d = (_c = (_b = store.state.config) === null || _b === void 0 ? void 0 : _b.franchise) === null || _c === void 0 ? void 0 : _c.dade) === null || _d === void 0 ? void 0 : _d.apiKey)
      ? store.state.config.franchise.dade.apiKey
      : (_f = (_e = store.state.config) === null || _e === void 0 ? void 0 : _e.dade) === null || _f === void 0 ? void 0 : _f.apiKey;
    this.url = ((_g = store.state === null || store.state === void 0 ? void 0 : store.state.job) === null || _g === void 0 ? void 0 : _g.isFranchise) && ((_k = (_j = (_h = store.state.config) === null || _h === void 0 ? void 0 : _h.franchise) === null || _j === void 0 ? void 0 : _j.dade) === null || _k === void 0 ? void 0 : _k.url)
      ? store.state.config.franchise.dade.url
      : (_m = (_l = store.state.config) === null || _l === void 0 ? void 0 : _l.dade) === null || _m === void 0 ? void 0 : _m.url;
    this.amount = undefined;
    this.userId = (_o = store.state === null || store.state === void 0 ? void 0 : store.state.session) === null || _o === void 0 ? void 0 : _o.uid;
    this.paymentId = undefined;
    this.loading = false;
    this.payment = undefined;
    this.checkFront = this.defaultCheckImage;
    this.checkBack = this.defaultCheckImage;
    this.errors = [];
    this.isScanningFront = true;
    this.isHovered = false;
    this.hasCheckFront = false;
    this.hasCheckBack = false;
  }
  onUrlChange() {
    this.startScanner();
  }
  async startScanner() {
    if (this.apiKey && this.url) {
      this.dade = new DadeMobile(this.apiKey, this.url);
      try {
        this.payment = await this.dade.stagePayment({
          external_user_id: "0",
          external_reference: this.paymentId ? this.paymentId : "0",
          amount: this.amount ? this.amount : 0,
        });
      }
      catch (error) {
        console.log(error);
      }
    }
    else {
      console.log("Must provide Dade API key and url!");
    }
  }
  async componentDidLoad() {
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser))
      return;
    this.startScanner();
  }
  selectFile(event, imageFile) {
    this.errors = [];
    this.loading = true;
    const file = imageFile
      ? imageFile
      : event && event.srcElement && event.srcElement.files
        ? event.srcElement.files[0]
        : null;
    const reader = new FileReader();
    reader.onload = async () => {
      try {
        await this.dade.uploadImage(this.payment, this.isScanningFront ? "checkfront" : "checkrear", reader.result.split(",")[1]);
        if (this.isScanningFront) {
          this.hasCheckFront = true;
          this.checkFront = reader.result;
        }
        else {
          this.hasCheckBack = true;
          this.checkBack = reader.result;
        }
        this.isScanningFront = !this.isScanningFront;
        this.ftCheckScan.emit({
          event,
          front: this.checkFront,
          back: this.checkBack,
        });
        this.loading = false;
      }
      catch (error) {
        console.log(error);
      }
    };
    reader.onerror = () => {
      alert("Error opening image file!");
      this.loading = false;
    };
    if (file) {
      reader.readAsDataURL(file);
    }
  }
  onFlip(event) {
    console.log(event.detail);
    this.isScanningFront = !event.detail.flipped;
  }
  async openCamera(scanningBack) {
    this.isScanningFront = !scanningBack;
    if (this.fileInputEl) {
      this.fileInputEl.click();
    }
  }
  async confirmPayment(options = {}) {
    try {
      this.loading = true;
      const confirmation = await this.dade.confirmPayment(this.payment, options);
      await this.save(null);
      this.ftCheckConfirmation.emit({ confirmation });
      this.loading = false;
    }
    catch (error) {
      this.errors = error.errors;
      this.ftCheckError.emit({ event, error, payment: this.payment });
      throw new Error(error.errors[0].error_message);
    }
    return this.payment;
  }
  async save(event) {
    this.errors = [];
    if (!this.hasCheckFront || !this.hasCheckBack) {
      alert(`Please take a picture of the ${!this.hasCheckFront ? "front" : "back"} of the check.`);
      this.isScanningFront = !this.hasCheckFront ? true : false;
      return false;
    }
    if (!this.amount) {
      alert("Please the amount that the check is made out for.");
      return false;
    }
    try {
      this.payment = await this.dade.setAmount(this.payment, this.amount);
      this.ftSubmitCheck.emit({ event, data: { payment: this.payment } });
    }
    catch (error) {
      this.errors = error.errors;
      this.ftCheckError.emit({ event, error, payment: this.payment });
    }
    this.loading = false;
  }
  cancel(event) {
    this.ftCancel.emit({ event });
  }
  async flipCard() {
    this.isScanningFront = !this.isScanningFront;
  }
  onDrop(event) {
    event.preventDefault();
    if (event.dataTransfer &&
      event.dataTransfer.files &&
      event.dataTransfer.files.length > 0) {
      this.selectFile(event, event.dataTransfer.files[0]);
      this.isHovered = false;
    }
  }
  onDrag(event) {
    event.preventDefault();
  }
  onDragEnter(_event) {
    this.isHovered = true;
  }
  onDragLeave(_event) {
    this.isHovered = false;
  }
  onSubmit(event) {
    event.preventDefault();
  }
  render() {
    return (index.h("form", { id: "form-check", onDrop: (event) => this.onDrop(event), onDragOver: (event) => this.onDrag(event), onDragEnter: (event) => this.onDragEnter(event), onDragLeave: (event) => this.onDragLeave(event), onSubmit: (event) => this.onSubmit(event) }, this.errors.map((error) => (index.h("floodteam-error", { message: error.error_message }))), index.h("input", { ref: (el) => (this.fileInputEl = el), type: "file", accept: "image/*", onChange: (event) => this.selectFile(event), capture: "camera" }), index.h("div", { class: "check-scanner-preview check-front", onClick: () => this.openCamera(), style: {
        background: `url(${this.checkFront})`,
      } }, index.h("ion-button", null, "Upload Front")), index.h("div", { class: "check-scanner-preview check-back", onClick: () => this.openCamera(true), style: {
        background: `url(${this.checkBack})`,
      } }, index.h("ion-button", null, "Upload Back"))));
  }
  get payCheckEl() { return index.getElement(this); }
  static get watchers() { return {
    "url": ["onUrlChange"]
  }; }
};
PayCheck.style = payCheckCss;

exports.fireenjin_input_amount = InputAmount;
exports.floodteam_pay_card = PayCard;
exports.floodteam_pay_check = PayCheck;
