const setCookie = (name, value) => {
  var Days = 100
  var exp = new Date()
  exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000)
  document.cookie = name + '=' + escape(value) + ';expires=' + exp.toGMTString() + ';Path=/'
  // document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString()+ ";Path=/home";
}

const getCookie = (name) => {
  var arr,
    reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
  if ((arr = document.cookie.match(reg))) return unescape(arr[2])
  else return null
}

function WriteCookie(name) {
  var now = new Date()
  now.setMonth(now.getMonth() - 1)
  // cookievalue = escape(document.myform.customer.value) + ";"

  document.cookie = name + '=' + '' + ';Path=/'
  document.cookie = 'expires=' + now.toUTCString() + ';Path=/'
  // document.write("Setting Cookies : " + "name=" + cookievalue );
}
function clonAllCookie() {
  var cookies = document.cookie.split(';')

  for (var i = 0; i < cookies.length; i++) {
    var cookie = cookies[i]
    var eqPos = cookie.indexOf('=')
    var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie
    document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'
  }
}
export { setCookie, getCookie, WriteCookie, clonAllCookie }
