'use strict';

var Plaid = require('./Plaid-CPESyiiV.js');
var utils = require('./utils-BsnepLy6.js');
var index = require('./index-p7cvUYAE.js');
var badge = require('./badge-GBNtUypt.js');

const makeGetPayoutCSV = ({ authToken, service }) => async ({ payoutId, onError }) => {
    try {
        const { data } = await service.fetchCSV(payoutId, authToken);
        const a = document.createElement('a');
        a.href = data.csv_url;
        a.click();
    }
    catch (error) {
        const errorMessage = utils.getErrorMessage(error);
        const code = utils.getErrorCode(error === null || error === void 0 ? void 0 : error.code);
        onError({
            error: errorMessage,
            code,
            severity: Plaid.ComponentErrorSeverity.ERROR,
        });
    }
};

const MapPayoutStatusToBadge = (status) => {
    const statusToBadgeProps = {
        canceled: {
            variant: badge.BadgeVariant.DANGER,
            title: 'Transfer to your bank account failed',
            text: 'Canceled',
        },
        failed: {
            variant: badge.BadgeVariant.DANGER,
            title: 'Transfer to your bank account failed',
            text: 'Failed',
        },
        forwarded: {
            variant: badge.BadgeVariant.SECONDARY,
            title: 'This payout initially failed; the funds have been forwarded to your next successful payout',
            text: 'Forwarded',
        },
        in_transit: {
            variant: badge.BadgeVariant.PRIMARY,
            title: 'Transfer to your bank account has been initiated',
            text: 'In Transit',
        },
        paid: {
            variant: badge.BadgeVariant.SUCCESS,
            title: 'Successfully deposited into your bank account',
            text: 'Paid',
        },
        pending: {
            variant: badge.BadgeVariant.PRIMARY,
            title: 'Batched and scheduled to be transferred',
            text: 'Pending',
        },
        scheduled: {
            variant: badge.BadgeVariant.PRIMARY,
            title: 'Batched and scheduled to be transferred',
            text: 'Scheduled',
        },
        withdrawn: {
            variant: badge.BadgeVariant.SUCCESS,
            title: 'Negative payout balance successfully withdrawn from your bank account',
            text: 'Withdrawn',
        },
    };
    const badgeProps = statusToBadgeProps[status];
    return index.h(badge.Badge, Object.assign({}, badgeProps));
};

exports.MapPayoutStatusToBadge = MapPayoutStatusToBadge;
exports.makeGetPayoutCSV = makeGetPayoutCSV;
