const getCookie = function getCookie(cname) {
  try {
    const name = `${cname}=`;
    const decodedCookie = decodeURIComponent(window.document.cookie);
    const ca = decodedCookie.split(';');
    /* Until I rewrite these cookie utils, just going to leave as demo on w3 */
    /* eslint-disable-next-line no-plusplus */
    for (let i = 0; i < ca.length; i++) {
      let c = ca[i];
      while (c.charAt(0) === ' ') {
        c = c.substring(1);
      }
      if (c.indexOf(name) === 0) {
        return c.substring(name.length, c.length);
      }
    }
  } catch (error) {
    return '';
  }
  return '';
};
export default getCookie;