"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.destination = void 0;
const tslib_1 = require("tslib");
const shim_1 = require("../../runtime/shim");
const actions_core_1 = require("@segment/actions-core");
const trackCustomer_1 = tslib_1.__importStar(require("./trackCustomer"));
const trackPurchase_1 = tslib_1.__importStar(require("./trackPurchase"));
const trackSignUp_1 = tslib_1.__importStar(require("./trackSignUp"));
const trackPage_1 = tslib_1.__importStar(require("./trackPage"));
const trackCustomEvent_1 = tslib_1.__importDefault(require("./trackCustomEvent"));
const actions_shared_1 = require("@segment/actions-shared");
const presets = [
    {
        name: 'Track Customer',
        subscribe: trackCustomer_1.trackCustomerDefaultSubscription,
        partnerAction: 'trackCustomer',
        mapping: actions_core_1.defaultValues(actions_shared_1.trackCustomerFields)
    },
    {
        name: 'Track Purchase',
        subscribe: trackPurchase_1.trackPurchaseDefaultSubscription,
        partnerAction: 'trackPurchase',
        mapping: actions_core_1.defaultValues(trackPurchase_1.browserTrackPurchaseFields)
    },
    {
        name: 'Track Sign Up',
        subscribe: trackSignUp_1.trackSignUpDefaultSubscription,
        partnerAction: 'trackSignUp',
        mapping: actions_core_1.defaultValues(trackSignUp_1.browserTrackSignUpFields)
    },
    {
        name: 'Track Page',
        subscribe: trackPage_1.trackPageDefaultSubscription,
        partnerAction: 'trackPage',
        mapping: actions_core_1.defaultValues(trackPage_1.trackPageFields)
    }
];
exports.destination = {
    name: 'Friendbuy (Actions)',
    slug: 'actions-friendbuy',
    mode: 'device',
    settings: {
        merchantId: {
            label: 'Friendbuy Merchant ID',
            description: 'Find your Friendbuy Merchant ID by logging in to your [Friendbuy account](https://retailer.friendbuy.io/) and going to Developer Center > Friendbuy Code.',
            type: 'string',
            format: 'uuid',
            required: true
        }
    },
    initialize: async ({ settings }, dependencies) => {
        let friendbuyAPI;
        window.friendbuyAPI = friendbuyAPI = window.friendbuyAPI || [];
        const friendbuyBaseHost = window.friendbuyBaseHost ?? 'fbot.me';
        friendbuyAPI.merchantId = settings.merchantId;
        friendbuyAPI.push(['merchant', settings.merchantId]);
        void dependencies.loadScript(`https://static.${friendbuyBaseHost}/friendbuy.js`);
        void dependencies.loadScript(`https://campaign.${friendbuyBaseHost}/${settings.merchantId}/campaigns.js`);
        return friendbuyAPI;
    },
    presets,
    actions: {
        trackCustomer: trackCustomer_1.default,
        trackPurchase: trackPurchase_1.default,
        trackSignUp: trackSignUp_1.default,
        trackPage: trackPage_1.default,
        trackCustomEvent: trackCustomEvent_1.default
    }
};
exports.default = shim_1.browserDestination(exports.destination);
//# sourceMappingURL=index.js.map