/* eslint-disable */

declare var branch: Branch.BranchGlobal;

// Disable this since branch.io seems to think the best idea is to give everyone pre-minified code instead of actual docs.
// prettier-ignore
export function initializeBranch(apiKey: string, options: Branch.BranchOptions): void {
  // prettified version of copy/pasted code
  ((b: { [key: string]: any}, r: Document, a: string, n: string, c: Function, h: object, _: string[], s: number, d?: HTMLScriptElement, k?: any) => { // tslint:disable-line:ban-types
    if (!b[n] || !b[n]._q) {
      for (; s < _.length; ) {
        c(h, _[s++]);
      }
      d = r.createElement(a) as HTMLScriptElement;
      d.async = true;
      d.src = 'https://cdn.branch.io/branch-latest.min.js';
      k = r.getElementsByTagName(a)[0];
      k.parentNode.insertBefore(d, k);
      b[n] = h;
    }
  })(
    window,
    document,
    'script',
    'branch',
    (b: any, r: any) => {
      b[r] = function(): void { // tslint:disable-line:only-arrow-functions
        b._q.push([r, arguments]);
      };
    },
    { _q: [], _v: 1 },
    'addListener applyCode autoAppIndex banner closeBanner closeJourney creditHistory credits data deepview deepviewCta first getCode init link logout redeem referrals removeListener sendSMS setBranchViewData setIdentity track validateCode trackCommerceEvent'.split(
      ' '
    ),
    0
  );
  // init Branch
  branch.init(apiKey, options);
}
