import type { ProductStatus } from '@/pages/ProductList/data';

type ProductAccessTarget = {
  status: ProductStatus;
};

export default (initialState: API.UserInfo | undefined) => {
  // 在这里按照初始化数据定义项目中的权限，统一管理
  // 参考文档 https://umijs.org/docs/max/access
  const canSeeAdmin = !!initialState && initialState.name !== 'dontHaveAccess';
  const canManageProduct = canSeeAdmin;

  return {
    canSeeAdmin,
    canManageProduct,
    canEditProduct: canManageProduct,
    canBatchUpdateProductStatus: canManageProduct,
    canViewCostPrice: canSeeAdmin,
    canDeleteProduct: (product: ProductAccessTarget) =>
      canManageProduct && ['draft', 'offline'].includes(product.status),
  };
};
