"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.search = search;

var _selectn = require("selectn");

var _selectn2 = _interopRequireDefault(_selectn);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/* global encounterTemplateV2User */
function search(url, query, optionsMapping) {
  var authObj = {
    DoctorCompanyId: encounterTemplateV2User.DoctorCompanyId,
    Token: encounterTemplateV2User.AppLoginTokens[0].Token
  };

  var body = Object.assign(authObj, { Name: query });
  return fetch(url, {
    method: "POST",
    headers: {
      RequestInfo: "TestUser#TestPass#" + authObj.DoctorCompanyId + "##" + authObj.Token,
      "Content-Type": "application/json"
    },
    body: JSON.stringify(body)
  }).then(function (resp) {
    return resp.json();
  }).then(function (json) {
    return optionsMapping ? (0, _selectn2.default)(optionsMapping, json) : json;
  });
}