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 filterByProfession = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
    var filterQuery = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
    var hasMore, filter, 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;
            }
            filter = '';

            if (filterByProfession && filterQuery.length) {
              filter = '&query=status:published%20AND%20customFields.profession:"' + filterQuery + '"';
            } else {
              filter = '&query=status:published';
            }

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

          case 7:
            response = _context.sent;
            _context.next = 10;
            return response.json();

          case 10:
            data = _context.sent;


            data.contentItems = data.contentItems.filter(function (course) {
              if (course.tags && course.tags[0] && course.tags[0].label == 'Hidden') {
                return false;
              }
              var customField = data.contentItems.map(function (each) {
                return each.customFields;
              });
              console.log(customField);

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

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

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

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

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

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

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

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

module.exports = getPtceActivities;
