import Cookies from 'js-cookie'

const TokenKey = 'Admin-TokenS'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}


export const PermissionEnum = {
  PRESCRIBE_ADD: 'prescribe:add',       // 新增处方（西药+中药）
  PRESCRIBE_EDIT: 'prescribe:edit',     // 编辑处方
  PRESCRIBE_DELETE: 'prescribe:delete', // 删除处方
  PRESCRIBE_CREATE: 'prescribe:create'  // 开处方
};


const rolePermissions = {
  doctor: [ // 普通医生
    PermissionEnum.PRESCRIBE_ADD,
    PermissionEnum.PRESCRIBE_EDIT,
    PermissionEnum.PRESCRIBE_CREATE
  ],
  nurse: [ // 护士
    PermissionEnum.PRESCRIBE_CREATE
  ]
};


export const hasPermission = (targetPermission) => {
  const userRole = localStorage.getItem('userRole');
  if (!userRole || !rolePermissions[userRole]) return false;
  return rolePermissions[userRole].includes(targetPermission);
};
