import _message from "antd/es/message";
import copy from "copy-to-clipboard";
export var getCookie = function getCookie(field) {
  var cook = document.cookie.split('; ');
  var cookieIndex = cook.findIndex(function (o) {
    return o.match(field) !== null;
  });
  var fieldValue = cookieIndex >= 0 ? cook[cookieIndex].split('=')[1] : undefined;
  return fieldValue ? decodeURIComponent(fieldValue) : undefined;
};
export function setCookie(field, value, expiredays) {
  var exdate = new Date();
  exdate.setDate(exdate.getDate() + expiredays);
  var expires = expiredays === undefined ? "" : ";expires=" + exdate.toGMTString();
  document.cookie = field + "=" + encodeURIComponent(value) + expires + ";path=/";
}
export var clearCookie = function clearCookie() {
  var keys = document.cookie.match(/[^ =;]+(?=)/g);
  if (keys) {
    for (var i = keys.length; i--;) {
      document.cookie = keys[i] + '=0;path=/;expires=' + new Date(0).toUTCString(); //清除当前域名下的
      document.cookie = keys[i] + '=0;path=/;domain=' + document.domain + ';expires=' + new Date(0).toUTCString(); //清除当前域名下的
      document.cookie = keys[i] + '=0;path=/;domain=kevis.com;expires=' + new Date(0).toUTCString(); //清除一级域名下的或指定的
    }
  }
};

export var getUrlSearch = function getUrlSearch(field, search) {
  var url = search ? search.replace('?', '') : window.location.search.replace('?', '');
  var params = url.split('&');
  var item = params.filter(function (o) {
    return o.match(field + "=") !== null;
  });
  if (item.length) {
    return item[0].replace(field + "=", '');
  } else {
    return undefined;
  }
};
export var weibo = function weibo(title) {
  window.open("https://service.weibo.com/share/share.php?url=" + window.location.href + "?from=weibo&title=" + title);
};
export var HandleCopy = function HandleCopy() {
  copy(window.location.href);
  _message.success("复制成功");
};