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B,EAAK,CAAEmC,OAAQ,QAUvCC,KAAM,CAACpC,EAAKqC,IAASlB,EAAUnB,EAAK,CAAEmC,OAAQ,OAAQE,KAAMC,KAAKC,UAAUF,KAE/E,C","sources":["webpack://stdcheck-exposed-wp-theme/./themes/stdcheck-exposed/src/js/utils.js","webpack://stdcheck-exposed-wp-theme/./themes/stdcheck-exposed/src/js/components/std-testing-center.js","webpack://stdcheck-exposed-wp-theme/./themes/stdcheck-exposed/src/js/services/http.js"],"sourcesContent":["/**\n * Utils class for common methods.\n */\nexport function Utils() {\n  /**\n   * Selects a lab hours table from the page.\n   *\n   * @param {number} i              The lab hours table to select from the page.\n   * @param {string} tableSelector  The table selector to get the html element\n   */\n  function getHoursTable(i, tableSelector) {\n    return $(tableSelector).eq(i);\n  }\n\n  /**\n   * Shows a lab hours table.\n   *\n   * @param {number} i              The lab hours table to show on the page.\n   * @param {string} tableSelector  The table selector to get the html element\n   */\n  function showHoursTable(i, tableSelector) {\n    getHoursTable(i, tableSelector).show();\n  }\n\n  /**\n   * Hide a lab hours table.\n   *\n   * @param {number} i              The lab hours table to hide on the page.\n   * @param {string} tableSelector  The table selector to get the html element\n   */\n  function hideHoursTable(i, tableSelector) {\n    getHoursTable(i, tableSelector).hide();\n  }\n\n  /**\n   * Add listener and action to the show/hours HTML element\n   *\n   * @param {string} elementClass   Class selector to get the element\n   * @param {string} tableSelector  The table selector to get the html element\n   */\n  function showHoursListener(elementClass, tableSelector) {\n    $(elementClass).each(function (i, elem) {\n      $(elem.children[0]).on('click', function () {\n        showHoursTable(i, tableSelector);\n        $(elem.children[0]).hide();\n        $(elem.children[1]).show();\n      });\n      $(elem.children[1]).on('click', function () {\n        hideHoursTable(i, tableSelector);\n        $(elem.children[1]).hide();\n        $(elem.children[0]).show();\n      });\n    });\n  }\n\n  /**\n   * Format date into AM - PM hours\n   *\n   * @param date\n   * @returns {string}\n   */\n  function formatAMPM(date) {\n    let hours = date.getHours();\n    let minutes = date.getMinutes();\n    const ampm = hours >= 12 ? 'PM' : 'AM';\n    hours = hours % 12;\n    hours = hours ? hours : 12; // the hour '0' should be '12'\n    minutes = minutes < 10 ? '0' + minutes : minutes;\n\n    return hours + ':' + minutes + ' ' + ampm;\n  }\n\n  return {\n    showHoursListener,\n    formatAMPM,\n  };\n}\n","import { HttpService } from '../services/http';\nimport { Utils } from '../utils';\n\n/**\n * JS component for actions on the page for each individual Lab\n */\nfunction TestCenterComponent() {\n  const httpService = new HttpService();\n  const utils = new Utils();\n  const nearLabsContainer = document.querySelector('#test-center-container');\n  const labPostalCode = document.querySelector('#labDetail').dataset.zip;\n\n  /**\n   * Get Labs near current Lab\n   */\n  function getLabsNearLab() {\n    httpService\n      .get(`${process.env.API_URL}/api/v1/labs/nearPostalCode?postalCode=${labPostalCode}&labCount=20`)\n      .then((response) => {\n        let labItems = '';\n        response.labs.forEach((lab) => (labItems += renderNearLabsItem(lab)));\n        nearLabsContainer.innerHTML = labItems;\n        utils.showHoursListener('.lab-item-show-hide', 'table.labHoursPsc');\n      });\n  }\n\n  /**\n   * RENDER psc html element\n   *\n   * @param psc        Object with the data from a lab\n   * @returns {string} String HTML element with lab information\n   */\n  function renderNearLabsItem(psc) {\n    const labTitle = psc.url?.url\n      ? `<a href='/std-testing-${psc.url.url}/'>${psc.address} ${psc.address2 ? psc.address2 : ''}</a>`\n      : `<span>${psc.address} ${psc.address2 ? psc.address2 : ''}</span>`;\n\n    let pscItem = `\n      <div class=\"column\">\n        <strong>\n          ${labTitle}\n        </strong>\n        <br />\n        ${psc.city} ${psc.state} ${psc.zip_code}\n        <br />\n        <strong>Distance:</strong> ${parseFloat(psc.distance).toFixed(2)} mile(s)\n        <br />\n        <span class=\"block\">\n          <strong>Hours:</strong>\n          <span class=\"hours-show-hide lab-item-show-hide\">\n            <span>Show Hours ▼</span>\n            <span>Hide Hours ▲</span>\n          </span>\n        </span>\n        <br />\n        <table class=\"labHours labHoursPsc labHours-small\">\n          <tbody>`;\n\n    psc.opening_hours.forEach((day) => {\n      const lunch = psc.lunch.find((lunch) => lunch.day === day.day);\n      pscItem += `\n            <tr>\n              <th>\n                <div class=\"${lunch ? '' : 'lab-hours-no-lunch'}\">\n                  ${day.day}\n                </div>\n                ${lunch ? '<div>Closed for lunch</div>' : ''}\n              </th>\n              <td>\n                <div class=\"${lunch ? '' : 'lab-hours-no-lunch'}\">\n                  ${utils.formatAMPM(new Date(day.start.date))} - ${utils.formatAMPM(new Date(day.end.date))}\n                </div>\n                ${\n                  lunch\n                    ? '<div>' +\n                      utils.formatAMPM(new Date(lunch.start.date)) +\n                      ' - ' +\n                      utils.formatAMPM(new Date(lunch.end.date)) +\n                      '</div>'\n                    : ''\n                }\n              </td>\n            </tr>\n          `;\n    });\n    pscItem += `</tbody></table><br /></div>`;\n\n    return pscItem;\n  }\n\n  getLabsNearLab();\n}\n\nwindow.testCenter = new TestCenterComponent();\n","/**\n * Service class for making HTTP requests\n */\nexport function HttpService() {\n  /**\n   * Make an HTTP request that expects a JSON response\n   *\n   * @param {*} url       The URL to make the request to\n   * @param {*} options   options for the fetch function\n   *\n   * @returns {Promise}   A promise that resolves with the JSON response data, or rejects for any of these reasons:\n   *                      1. The HTTP status code is not between 200-299\n   *                      2. The response is not valid JSON\n   *                      3. Network failures or anything that prevented the HTTP request from completing\n   */\n  function fetchJson(url, options = {}) {\n    options.headers = { Accept: 'application/json', 'Content-Type': 'application/json' };\n\n    return new Promise((resolve, reject) => {\n      fetch(url, options)\n        .then((response) => {\n          if (response.ok && response.status !== 204) {\n            response.json().then((data) => resolve(data));\n          } else if (response.ok && response.status === 204) {\n            resolve();\n          } else {\n            response.json().then((errorResponse) => {\n              errorResponse.code = response.status;\n              reject(errorResponse);\n            });\n          }\n        })\n        .catch((error) => reject(error));\n    });\n  }\n\n  return {\n    /**\n     * Make a GET request to the specified URL\n     *\n     * @param {string} url  The URL to make the request to\n     *\n     * @returns {Promise} A Promise that resolves with the response data when successful, and rejects on failure\n     */\n    get: (url) => fetchJson(url, { method: 'GET' }),\n\n    /**\n     * Make a POST request to the specified URL\n     *\n     * @param {string} url  The URL to make the request to\n     * @param {any} body    The request body\n     *\n     * @returns {Promise} A Promise that resolves with the response data when successful, and rejects on failure\n     */\n    post: (url, body) => fetchJson(url, { method: 'POST', body: JSON.stringify(body) }),\n  };\n}\n"],"names":["Utils","getHoursTable","i","tableSelector","$","eq","showHoursListener","elementClass","each","elem","children","on","show","showHoursTable","hide","hideHoursTable","formatAMPM","date","hours","getHours","minutes","getMinutes","ampm","window","testCenter","httpService","utils","nearLabsContainer","document","querySelector","labPostalCode","dataset","zip","get","then","response","labItems","labs","forEach","lab","psc","pscItem","url","address","address2","city","state","zip_code","parseFloat","distance","toFixed","opening_hours","day","lunch","find","Date","start","end","renderNearLabsItem","innerHTML","HttpService","fetchJson","options","headers","Accept","Promise","resolve","reject","fetch","ok","status","json","data","errorResponse","code","catch","error","method","post","body","JSON","stringify"],"sourceRoot":""}