"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isEmpty = exports.getWidgetOptions = exports.filterCustomTraits = exports.convertDateToUnix = void 0;
const tslib_1 = require("tslib");
const actions_core_1 = require("@segment/actions-core");
const actions_shared_1 = require("@segment/actions-shared");
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
function convertDateToUnix(created_at) {
    if (typeof created_at === 'number') {
        let unixDate = dayjs_1.default.unix(created_at).unix();
        if (unixDate.toString().length == 13) {
            unixDate = Math.floor(unixDate / 1000);
        }
        return unixDate;
    }
    return dayjs_1.default(created_at).unix();
}
exports.convertDateToUnix = convertDateToUnix;
function filterCustomTraits(traits) {
    const filteredCustomTraits = {};
    if (traits) {
        for (const [key, value] of Object.entries(traits)) {
            if (!actions_core_1.isArray(value) && !actions_core_1.isObject(value)) {
                filteredCustomTraits[key] = value;
            }
        }
    }
    return filteredCustomTraits;
}
exports.filterCustomTraits = filterCustomTraits;
function getWidgetOptions(hide_default_launcher, activator) {
    const widgetOptions = {};
    if (hide_default_launcher !== undefined) {
        widgetOptions.hide_default_launcher = hide_default_launcher;
    }
    if (activator !== '#IntercomDefaultWidget') {
        widgetOptions.widget = {
            activator: activator
        };
    }
    return widgetOptions;
}
exports.getWidgetOptions = getWidgetOptions;
function isEmpty(o) {
    return !actions_shared_1.isNonEmpty(o);
}
exports.isEmpty = isEmpty;
//# sourceMappingURL=utils.js.map