import { _ as _asyncToGenerator, r as regenerator } from './asyncToGenerator-958ef5fc.js';
import './_commonjsHelpers-0c4b6f40.js';
import './core.get-iterator-method-ea258bb1.js';
import './web.dom.iterable-ab4dea5c.js';
import './_library-528f1934.js';
import './_iter-detect-98db3b07.js';

var getPtceActivities = function () {
  var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(params) {
    var hasMore, response, data;
    return regenerator.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _context.prev = 0;
            hasMore = '';


            if (params.paginatedPoint && params.paginatedPoint !== '') {
              hasMore = '&cursor=' + params.paginatedPoint;
            }

            _context.next = 5;
            return fetch('https://www.pharmacytimes.org/incoming/v2/content?types[]=courses&sort=publishDate:desc&query=status:published&limit=25' + hasMore, {
              method: 'GET',
              headers: { Authorization: 'Bearer drnc4y57arj3f190cpvqiwxt3cxpbken' }
            });

          case 5:
            response = _context.sent;
            _context.next = 8;
            return response.json();

          case 8:
            data = _context.sent;


            data.contentItems = data.contentItems.filter(function (course) {
              if (course.tags && course.tags[0] && course.tags[0].label == 'Hidden') {
                return false;
              }

              var current_date = new Date();
              var courseEndDate = new Date(course.courseEndDate);

              return current_date.getTime() < courseEndDate.getTime();
            });

            return _context.abrupt('return', data);

          case 13:
            _context.prev = 13;
            _context.t0 = _context['catch'](0);

            console.log(_context.t0);
            return _context.abrupt('return', []);

          case 17:
          case 'end':
            return _context.stop();
        }
      }
    }, _callee, this, [[0, 13]]);
  }));

  return function getPtceActivities(_x) {
    return _ref.apply(this, arguments);
  };
}();

//import fetch from 'node-fetch'
var fetch = require('node-fetch').default;

module.exports = getPtceActivities;
