'use strict';

var index = require('./index-p7cvUYAE.js');
var payment_service = require('./payment.service-8Q-EEtXL.js');
var getPaymentDetails = require('./get-payment-details-_rinKLxh.js');
var Plaid = require('./Plaid-CPESyiiV.js');
var Analytics = require('./Analytics-C6KBHEIP.js');
var checkPkgVersion = require('./check-pkg-version-B9EoYyZR.js');
require('./config-state-BIgGhhe9.js');
var utils$1 = require('./utils-CYONRFR6.js');
require('./Pagination-Dediz133.js');
require('./Business-oBifyXkW.js');
var paymentsStatus = require('./payments-status-Bj_bCKUP.js');
var utils = require('./utils-8RGQVADu.js');
var styledHost = require('./styled-host-Ch0-dxF-.js');
require('./event-types-YOY5TKUN.js');
var skeleton = require('./skeleton-DvRCiQlA.js');
var badge = require('./badge-GBNtUypt.js');
require('./Api-D9vOcUw4.js');
require('./dinero-BwNN_k7x.js');
require('./utils-BsnepLy6.js');
require('./package-YyJzVqrh.js');
require('./index-W-zoNiyM.js');
require('./parts-BXshb_S-.js');

const PaymentDetailsLoading = () => (index.h("div", { class: "row gap-3" }, index.h("div", { class: "col-12" }, index.h(skeleton.Skeleton, { width: "35%", height: "30px" })), index.h("div", { class: "col-12" }, index.h(skeleton.Skeleton, { width: "70%" })), index.h("div", { class: "col-12" }, index.h(skeleton.Skeleton, { width: "40%" })), index.h("div", { class: "col-12" }, index.h(skeleton.Skeleton, { width: "40%" })), index.h("div", { class: "col-12" }, index.h(skeleton.Skeleton, { width: "100%" })), index.h("div", { class: "col-12" }, index.h(skeleton.Skeleton, { width: "80%" }))));

const JustifiPaymentDetails = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.errorEvent = index.createEvent(this, "error-event", 7);
        this.recordClickEvent = index.createEvent(this, "record-click-event", 7);
        this.loading = true;
    }
    componentWillLoad() {
        checkPkgVersion.checkPkgVersion();
        this.analytics = new Analytics.JustifiAnalytics(this);
        this.initializeGetPaymentDetails();
    }
    disconnectedCallback() {
        var _a;
        (_a = this.analytics) === null || _a === void 0 ? void 0 : _a.cleanup();
    }
    ;
    propChanged() {
        this.initializeGetPaymentDetails();
    }
    initializeGetPaymentDetails() {
        if (this.paymentId && this.authToken) {
            this.getPaymentDetails = getPaymentDetails.makeGetPaymentDetails({
                id: this.paymentId,
                authToken: this.authToken,
                service: new payment_service.PaymentService()
            });
            this.fetchData();
        }
        else {
            this.errorMessage = 'Payment ID and Auth Token are required';
            this.errorEvent.emit({
                message: this.errorMessage,
                errorCode: Plaid.ComponentErrorCodes.MISSING_PROPS,
                severity: Plaid.ComponentErrorSeverity.ERROR,
            });
        }
    }
    updateOnPropChange() {
        if (this.getPaymentDetails) {
            this.fetchData();
        }
    }
    fetchData() {
        this.loading = true;
        this.getPaymentDetails({
            onSuccess: ({ payment }) => {
                this.payment = payment;
                this.errorMessage = null;
            },
            onError: ({ error, code, severity }) => {
                this.errorMessage = error;
                this.errorEvent.emit({
                    errorCode: code,
                    message: error,
                    severity,
                });
            },
            final: () => {
                this.loading = false;
            },
        });
    }
    get PaymentStatus() {
        if (this.payment.status === Plaid.PaymentStatuses.disputed) {
            const disputeWasLost = this.payment.disputes.some((dispute) => dispute.status === Plaid.DisputeStatus.lost);
            if (disputeWasLost) {
                return paymentsStatus.PaymentStatusBadge.DISPUTE_LOST;
            }
        }
        return this.payment.status;
    }
    render() {
        return (index.h(styledHost.StyledHost, { key: 'f304cb665f17ce96b6d97a38d94907629f559413' }, this.loading && index.h(PaymentDetailsLoading, { key: '709acde31230bd9e825e4e9669234492aff3cc3a' }), !this.loading && this.errorMessage && utils.ErrorState(this.errorMessage), !this.loading && !this.errorMessage &&
            this.payment && (index.h("justifi-details", { key: '09a4a2559fb89a5b4b57d81b0fd48952c219d348', errorMessage: this.errorMessage }, index.h(utils.EntityHeadInfo, { key: '7cbfece91ce9e5fab75d561ad369080ecbe76fa4', slot: "head-info", badge: (index.h("div", { class: "d-flex gap-1" }, paymentsStatus.MapPaymentStatusToBadge(this.PaymentStatus), this.payment.expedited ? (index.h(badge.Badge, { variant: badge.BadgeVariant.WARNING, title: "Expedited", text: "Expedited" })) : null)), title: this.payment.formattedPaymentAmount(this.payment.amount) }, index.h(utils.EntityHeadInfoItem, { key: '4aa014d77def141d2053c3745b8215cc03a53ac7', classes: "border-1 border-end", title: "Updated At", value: `${utils$1.formatDate(this.payment.updated_at)} ${utils$1.formatTime(this.payment.updated_at)}` }), index.h(utils.EntityHeadInfoItem, { key: 'f344398f4fd4db6e1e7ca1335c3aa55630668475', classes: "border-1 border-end", title: "Created At", value: `${utils$1.formatDate(this.payment.created_at)} ${utils$1.formatTime(this.payment.created_at)}` }), index.h(utils.EntityHeadInfoItem, { key: 'a01e5a04400b996cfb2a9e563c8f383b8e8d7c66', title: "ID", value: this.payment.id })), index.h("div", { key: 'ef0c63d53031dfa8910dfbdedede1e20ac09e78a', slot: 'detail-sections' }, index.h(utils.DetailSectionTitle, { key: '5053784a7e3bd8932562a816921564aadd6d79c8', sectionTitle: "Details" }), index.h("div", { key: '43c56ee5a39589ea7a0107f32e274be439adf33a', class: "d-flex flex-column gap-2 w-100" }, index.h(utils.DetailItem, { key: 'fcee2dd211c9bf951cdd6855ac3fa844632391ce', title: "Amount", value: this.payment.formattedPaymentAmount(this.payment.amount) }), index.h(utils.DetailItem, { key: '44d055f3445f02feaeb4519b5f4777333089a8c6', title: "Fees", value: this.payment.formattedPaymentAmount(this.payment.fee_amount) }), index.h(utils.DetailItem, { key: '906b584174bd5c329974274a2f1e1ef7e9e8fde0', title: "Refunded", value: this.payment.formattedPaymentAmount(this.payment.amount_refunded) }), index.h(utils.DetailItem, { key: '809429e88eac8ebe8142bb0028f8b86447977697', title: "Net", value: this.payment.formattedPaymentAmount(this.payment.balance) }), index.h(utils.DetailItem, { key: 'e08c02efc64f105ce3180e9773584a331ae19a9b', title: "Status", value: paymentsStatus.MapPaymentStatusToBadge(this.PaymentStatus) }), index.h(utils.DetailItem, { key: 'fbb910b7006f9d4bff9b14ffd4fc2f7da8b68020', title: "Payment ID", value: this.payment.id }), index.h(utils.DetailItem, { key: '09fefc2d1a750ab2f5dfb2043db08d5f16d6d9aa', title: "Processing Fees", value: this.payment.formattedPaymentAmount(this.payment.fee_amount) }), index.h(utils.DetailItem, { key: '1d96f4557823f1d82d5c6e0e46a984c13c6f018b', title: "Statement Descriptor", value: this.payment.statement_descriptor }), index.h(utils.DetailItem, { key: '51bfae7ef30f36c99c0fa1b25dc5397720ef88ff', title: "Description", value: this.payment.description }), index.h(utils.DetailItem, { key: '5c44b3d40bfe6b2fbf258fee90f55ff24d0b3c28', title: "Expedited", value: this.payment.expedited ? 'Yes' : 'No' })), this.payment.payment_method.card && [
            index.h(utils.DetailSectionTitle, { key: '3d652ba331824448b7e7af969b2ead216f358e28', sectionTitle: "Payment Method" }),
            index.h("div", { key: '49ad00ec9d703d196a025fa17b03f4af7cdc4dc5', class: "d-flex flex-column gap-2 w-100" }, index.h(utils.DetailItem, { key: '2b1b3f57e74fd65dc4b82d727a94afbe14803c52', title: "ID", value: this.payment.payment_method.card.id }), index.h(utils.DetailItem, { key: 'b23d5263566ff11d469dea9a245d20a7689540f8', title: "Payment Type", value: "Card" }), index.h(utils.DetailItem, { key: 'f5f76d6d9ac609884aac18fe2743d4fad2192b86', title: "Last 4 Numbers", value: this.payment.payment_method.lastFourDigits }), index.h(utils.DetailItem, { key: '22f296966b6f1aaf516b1d70144cff4f59b82c05', title: "Brand", value: utils$1.snakeCaseToHumanReadable(this.payment.payment_method.card.brand) }), index.h(utils.DetailItem, { key: 'd7dcd0f7a74ed2cc5ba6406a7d48522ca06a7546', title: "Cardholder", value: this.payment.payment_method.payersName }))
        ], this.payment.payment_method.bank_account && [
            index.h(utils.DetailSectionTitle, { key: '37a2a20c462cb94baa01ca7763d43ced04b4543c', sectionTitle: "Payment Method" }),
            index.h("div", { key: 'f6de7746d5ff64d27368edef51b3c4e0ff7c658b', class: "d-flex flex-column gap-2 w-100" }, index.h(utils.DetailItem, { key: '34e9b26c6d20e9b5e86e4cc11fb925ff1ef5ce94', title: "ID", value: this.payment.payment_method.bank_account.id }), index.h(utils.DetailItem, { key: '32cd6da4d7234aca403bd699de23e1cf889bf14f', title: "Last 4 Numbers", value: this.payment.last_four_digits }), index.h(utils.DetailItem, { key: 'f1313ac7c15d5ae2d9dfa2b6d3ec794d0987252b', title: "Bank Name", value: this.payment.payment_method.bank_account.brand }), index.h(utils.DetailItem, { key: '76d1ac1961e530a7a6e1ba5512b982cd70df9470', title: "Account Owner", value: this.payment.payment_method.payersName }))
        ], this.payment.metadata && [
            index.h(utils.DetailSectionTitle, { key: '1cff262d07acda5bc742f325a23f4199c22f3a01', sectionTitle: 'Metadata' }),
            index.h("div", { key: '77379785d2559d39a26a253757fdaf02795c53a1', class: "d-table gap-2 w-100" }, index.h(utils.CodeBlock, { key: '92cb32f3dd6b45094210194e2e40927d7f9d6bde', metadata: this.payment.metadata }))
        ])))));
    }
    static get watchers() { return {
        "paymentId": ["propChanged"],
        "authToken": ["propChanged"],
        "getPaymentDetails": ["updateOnPropChange"]
    }; }
};

exports.justifi_payment_details = JustifiPaymentDetails;
