"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const config = require("config");
const country_tools_1 = require("country-tools");
function getCustomerBillingAddress(customer) {
    if (!customer.defaultBillingAddressId &&
        customer.billingAddressIds.length === 0) {
        return;
    }
    const addressId = customer.defaultBillingAddressId
        ? customer.defaultBillingAddressId
        : customer.billingAddressIds[0];
    return customer.addresses.find(address => address.id === addressId);
}
exports.getCustomerBillingAddress = getCustomerBillingAddress;
function getCustomerShippingAddress(customer) {
    if (!customer.defaultShippingAddressId &&
        customer.shippingAddressIds.length === 0) {
        return;
    }
    const addressId = customer.defaultShippingAddressId
        ? customer.defaultShippingAddressId
        : customer.shippingAddressIds[0];
    return customer.addresses.find(address => address.id === addressId);
}
exports.getCustomerShippingAddress = getCustomerShippingAddress;
function getCustomerCurrency(customer) {
    const currencies = config.get('store.supportedCurrencies');
    const defaultCurrency = config.get('store.defaultCurrency');
    const address = getCustomerShippingAddress(customer);
    if (address === undefined) {
        return defaultCurrency;
    }
    const currency = country_tools_1.getCurrencyFromIso2(address.country);
    if (currency === null || currencies.indexOf(currency) === -1) {
        return defaultCurrency;
    }
    return currency;
}
exports.getCustomerCurrency = getCustomerCurrency;
//# sourceMappingURL=customers.js.map