"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.writeReferredBy = exports.deleteReferredBy = exports.getReferredBy = exports.REFERRAL_ID_NAME = void 0;

var _milliseconds = _interopRequireDefault(require("milliseconds"));

var _cookie = require("./cookie");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// @ts-check
const domain = globalThis.location && globalThis.location.hostname.split('.').slice(-2).join('.') || 'xchart.com';
const REFERRAL_ID_NAME = 'ref_id';
exports.REFERRAL_ID_NAME = REFERRAL_ID_NAME;

const getReferredBy = () => (0, _cookie.readCookie)(REFERRAL_ID_NAME);

exports.getReferredBy = getReferredBy;

const deleteReferredBy = () => (0, _cookie.deleteCookie)(REFERRAL_ID_NAME, domain);

exports.deleteReferredBy = deleteReferredBy;

const writeReferredBy = str => {
  try {
    (0, _cookie.writeCookie)(REFERRAL_ID_NAME, str, {
      maxAge: _milliseconds.default.years(10),
      domain
    });
  } catch (e) {// intentionally not used
  }
};

exports.writeReferredBy = writeReferredBy;