'use strict';

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

const index = require('./index-fd2bbf0b.js');
const hardwareBackButton = require('./overlays-de05dc6a.js');
const store = require('./store-03756ad8.js');
const index$1 = require('./index-6307644b.js');
require('./ionic-global-1340f737.js');
require('./helpers-c2496722.js');
require('./index-81aa1bcb.js');
require('./getCache-c039a6ae.js');
require('./_commonjsHelpers-a5111d61.js');
require('./logic-d8c34975.js');

const appPaymentListCss = "";

let AppPaymentList = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.methodIcons = { check: "create", manual: "cash", card: "card" };
  }
  onChange(event) {
    var _a;
    if (((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.tagName) === "ION-SEARCHBAR") {
      this.paginationEl.query = event.detail.value ? event.detail.value : "";
    }
  }
  formatUSD(amount) {
    const formatter = new Intl.NumberFormat("en-US", {
      style: "currency",
      currency: "USD",
      minimumFractionDigits: 2,
    });
    return formatter.format(amount ? amount : 0);
  }
  async openPayCalculatorModal(amount, jobId) {
    var _a, _b, _c;
    this.payCalculatorModalEl = await hardwareBackButton.modalController.create({
      component: "modal-pay-calculator",
      componentProps: {
        amount,
        disableAmount: true,
        disableReferral: true,
        jobId,
        payModelId: ((_c = (_b = (_a = store.state === null || store.state === void 0 ? void 0 : store.state.profile) === null || _a === void 0 ? void 0 : _a.location) === null || _b === void 0 ? void 0 : _b.defaultPayModel) === null || _c === void 0 ? void 0 : _c.id) || null,
      },
    });
    return this.payCalculatorModalEl.present();
  }
  async componentDidLoad() {
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser))
      return;
  }
  render() {
    return [
      index.h("ion-content", { class: "ion-padding" }, index.h("floodteam-title-bar", null, index.h("ion-router-link", { href: "/payments" }, "Payments"), index.h("ion-buttons", { slot: "end" }, index.h("ion-button", { fill: "solid", color: "primary", href: "/payments/new" }, "Add"))), index.h("fireenjin-search-bar", { ref: (el) => (this.filterBarEl = el), paginationEl: this.paginationEl, filters: [
          {
            name: "paymodelId",
            label: "Pay Model",
            endpoint: "listPayModels",
            icon: "pie-chart",
            resultsKey: "payModels",
          },
          {
            name: "locationId",
            label: "Location",
            endpoint: "listLocations",
            value: this.locationId,
            icon: "business",
            resultsKey: "locations",
          },
          {
            name: "method",
            label: "Payment Method",
            icon: "pricetags",
            multiple: true,
            options: [
              {
                label: "Check",
                value: "check",
              },
              {
                label: "Manual",
                value: "manual",
              },
              {
                label: "Card",
                value: "card",
              },
            ],
          },
        ] }), index.h("fireenjin-pagination", { ref: (el) => (this.paginationEl = el), endpoint: "listPayments", display: "list", limit: 24, resultsKey: "payments", listEl: ({ result: payment }) => {
          var _a, _b;
          return (index.h("ion-item", null, (payment === null || payment === void 0 ? void 0 : payment.method) && this.methodIcons[payment.method] && (index.h("ion-icon", { slot: "start", color: "medium", name: this.methodIcons[payment.method] })), index.h("ion-label", null, index.h("h2", null, (_a = payment.job) === null || _a === void 0 ? void 0 : _a.title), index.h("p", null, this.formatUSD(payment.amount), " paid by ", payment.method), index.h("div", null, index.h("ion-button", { fill: "clear", href: `/jobs/${(_b = payment.job) === null || _b === void 0 ? void 0 : _b.id}`, target: "_blank" }, "Open Job"))), payment.createdAt && (index.h("span", { slot: "end" }, index.h("div", { style: {
              textAlign: "center",
            } }, index$1.format(new Date(Date.parse(payment.createdAt)), "MM/dd/yyyy")), index.h("ion-button", { style: {
              display: "block",
            }, size: "small", fill: "clear", onClick: () => {
              var _a;
              return this.openPayCalculatorModal(payment === null || payment === void 0 ? void 0 : payment.amount, (_a = payment === null || payment === void 0 ? void 0 : payment.job) === null || _a === void 0 ? void 0 : _a.id);
            } }, "Process", index.h("ion-icon", { slot: "end", name: "pie-chart" }))))));
        } })),
      index.h("floodteam-navigation-footer", null),
    ];
  }
};
AppPaymentList.style = appPaymentListCss;

exports.app_payment_list = AppPaymentList;

//# sourceMappingURL=app-payment-list.cjs.entry.js.map