{"size": 1439, "ext": "js", "max_stars_repo_path": "_sass/pbsorg/components/campaign-modal/campaign-modal.js", "max_stars_repo_name": "pbs/alexandria", "max_stars_repo_stars_event_min_datetime": "2017-03-16T11:41:22.000Z", "max_stars_repo_stars_event_max_datetime": "2017-03-16T11:41:22.000Z", "max_issues_repo_path": "_sass/pbsorg/components/campaign-modal/campaign-modal.js", "max_issues_repo_name": "pbs/alexandria", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "_sass/pbsorg/components/campaign-modal/campaign-modal.js", "max_forks_repo_name": "pbs/alexandria", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.803030303, "max_line_length": 163, "alphanum_fraction": 0.6712995136}
'use strict';

import $ from 'jquery';
import * as CampaignModalLogic from './campaign-modal-child';
import Modal from '../modal/modal';

let _campaignModal;

/**
 * Creates modal
 */
const _setupCampaignModal = () => {

  const options = {
    modalId: '#campaignModal',
    focusTarget: '#modal-campaign__dialog',
    childView: CampaignModalLogic
  };

  _campaignModal = new Modal(options);

};

/**
 * Shows modal
 */
const _showTimedPopup = () => {
  _campaignModal.show();
};

/**
 * Validates against cookies as to whether a user should be shown a modal
 */
const _validateDonateCampaign = () => {
  let cookieValue = 0;

  cookieValue = !isNaN(parseInt(readCookie('pbs.donateCampaign.counter'))) ? parseInt(readCookie('pbs.donateCampaign.counter')) : 0;

  if ( cookieValue >= 3 || readCookie('pbs.donateCampaign.dontShowToday') || readCookie('pbs.donateCampaign.donated') || $('.pbs-stastions-list').is(':visible')) {
  } else {
    let campaign_start = new Date(PBS.donateCampaign.start);
    let campaign_end = new Date(PBS.donateCampaign.end);

    let campaign_today = new Date();

    campaign_start.setHours(0,0,1);
    campaign_end.setHours(23,59,59);

    if (readCookie("pbsol.station") && campaign_today >= campaign_start && campaign_today <= campaign_end) {
      _showTimedPopup();
    }
  }
};

/**
 * Initializes
 */
const init = () => {

  _setupCampaignModal();
  _validateDonateCampaign();

};

export { init };
