export function setCookie (name, value, days) {
  let expires = '';
  if (days) {
    const date = new Date();
    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
    expires = '; expires=' + date.toGMTString();
  }
  document.cookie = name + '=' + value + ';' + expires;
}

export function getCookie (name) {
  const value = '; ' + document.cookie;
  const parts = value.split('; ' + name + '=');
  return (parts.length === 2) ? parts.pop().split(';').shift() : '';
}

export function deleteCookie (name) {
  setCookie(name, '', -1);
}

export function sortArrayOfObjectsByKey (inputArray, Key) {
  return inputArray.sort(
		(obj1, obj2) => parseFloat(obj1[Key]) - parseFloat(obj2[Key])
	);
}

export function prepareOptionsForReactSelect(object,defaultValue,defaultLabel){
  let options = [{'value':defaultValue,'label':defaultLabel}];
  for(let key in object){
    options.push({'value':key,'label':object[key]});
  }
  return options;
}

export function prepareButtonsForButtonGroup (list) {
  let buttons = [];
  for(let i=0;i<list.length;i++){
    buttons.push({'name':list[i].fare});
  }
  return buttons;
}

export function getCurrentScreenSize(){
 var xs=768,sm=991,md=1199;
 var size=document.documentElement.clientWidth;
 return (size < xs) ?  'xs' : (size <= sm) ? 'sm' : (size <= md) ? 'md' : 'lg';
}

export default {
  setCookie,
  getCookie,
  deleteCookie,
  sortArrayOfObjectsByKey,
  prepareOptionsForReactSelect,
  prepareButtonsForButtonGroup,
  getCurrentScreenSize
};
