const TokenKey = 'A-Token'
const UserIdKey = 'userData'
const TypesKey = 'types'


export function getUserData () {
    return JSON.parse(localStorage.getItem(UserIdKey)); 
}
export function setUserData (data) {
     localStorage.setItem(UserIdKey,JSON.stringify(data))
}
export function getTyps (id) {
	 if(id){
		 var arr=JSON.parse(localStorage.getItem(TypesKey));
		 var item=arr.filter(element => {
		       return  typeof(id)=='string'?element.code==id:element.id==id
		 });
		 return item[0]
	 }else{
		 return JSON.parse(localStorage.getItem(TypesKey));
	 }
}

export function getIsCreator (key) {
	 let is=false;
	 getUserData().employee_detail.role_list.forEach(item=>{ 
		 if(key==item.name){
			 is=true;
		 }
	 })
	 return is
}

export function setTyps (data) {
     localStorage.setItem(TypesKey,JSON.stringify(data))
}

export function getToken () {
    return localStorage.getItem(TokenKey)
}

export function setToken (token) {
     localStorage.setItem(TokenKey, token)
}

