import { C as ComponentErrorSeverity } from './Plaid.js';
import { g as getErrorCode, a as getErrorMessage } from './utils3.js';
import { h } from '@stencil/core/internal/client';
import { B as Badge, a as BadgeVariant } from './badge.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 = getErrorMessage(error);
        const code = getErrorCode(error === null || error === void 0 ? void 0 : error.code);
        onError({
            error: errorMessage,
            code,
            severity: ComponentErrorSeverity.ERROR,
        });
    }
};

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

export { MapPayoutStatusToBadge as M, makeGetPayoutCSV as m };
