export function guid() {
  const chars = '0123456789abcdefghijklmnopqrstuvwxyz'
  const length = chars.length
  const randomString = (len) => {
    const array = new Uint8Array(len)
    crypto.getRandomValues(array)
    return Array.from(array)
      .map(byte => chars[byte % length])
      .join('');
  }
  return `${randomString(8)}${randomString(8)}${randomString(8)}${randomString(8)}`;
}

export function getRole() {
  const belongId = localStorage.getItem('belongId')
  if (belongId === 'D') return 0

  const roleListStr = localStorage.getItem('role')
  if (!roleListStr) return 4
  const roleList = JSON.parse(roleListStr)

  for (let role of roleList) {
    if (role.roleCode === 'SG0101') return 1
  }

  for (let role of roleList) {
   if (role.roleCode === 'SG0201') return 2
  }

  for (let role of roleList) {
    if (role.roleCode === 'SG0301') return 3
  }

  return 4
}