Source: index.js

/**
 * @namespace Main
 * @description start project npm i && npm start
 */

/**
 * @namespace Initiators
 */
import { FlipClockInitiator, UI, TagManager, DomService } from 'initiators';
import Parameters from 'utils/parameters';
import 'whatwg-fetch';

/**
 * @memberof Initiators
 * @constructor Promotion
 * @param {Object} args - arg only for FlipClock
 * @example
 * const promotion = new Promotion();
 */
export default class Promotion {
  args = {};

  /**
   * @method Promotion#run
   * @memberof Initiators
   * @description Run promotion banner
   * @example
   * const promotion = new Promotion();
   * promotion.run();
   */
  run = async () => {
    const el = DomService.get('.PlasmaPromotionJs');
    if (el === null) return;

    const parameters = new Parameters();
    this.args = parameters.parse('.PlasmaPromotionJs');
    if (this.args.promocodePageId) {
      await fetch(`/ajax/landing-promocode.php?page-id=${this.args.promocodePageId}`)
        .then(response => response.json())
        .then((data) => {
          if (data.status === 1) {
            this.args = parameters.update({
              startDate: data.promocode.start_date,
              endDate: data.promocode.expiration_date,
            });
          }
        })
        .catch(() => {});
    }
    const flipClock = new FlipClockInitiator(this.args);
    const tagManager = new TagManager(this.args);
    const banner = new UI.UiBanner(this.args);
    const popup = this.args.popupId !== '' ? new UI.UiPopup(this.args) : { run: () => {} };
    flipClock.run();
    banner.run(tagManager);
    popup.run(banner, tagManager);
    return {
      args: this.args,
      flipClock,
      banner,
      popup,
      tagManager,
    };
  }
}