import { Pipe, PipeTransform } from '@angular/core';
import { Right } from 'src/app/core/service/security/app-token.service';

@Pipe({
    name: 'role',
    pure: true
})
export class RolePipePipe implements PipeTransform {

    transform(userPermission: Right[], actionveRouteRole: string): boolean {

        // return true
        // if(DISABLED_ROLE.some(x => actionveRouteRole.toLowerCase().includes(x))) return true
        // if(userPermission.length && actionveRouteRole) return userPermission.some(x => x.obj.includes(actionveRouteRole))
        if(!userPermission?.length && !actionveRouteRole)    return false
        if(userPermission?.length && actionveRouteRole) {
            // console.log(actionveRouteRole)
            // console.log(userPermission.some(x => x.obj.includes(actionveRouteRole)))
            // console.log(userPermission.some(x => x.obj == actionveRouteRole))
            // return userPermission.some(x => x.obj.includes(actionveRouteRole))
            return userPermission.some(x => x.obj == actionveRouteRole)
        }
            // if(!actionveRouteRole.includes('-')) {
            //     let canAccess = userPermission.some(role => actionveRouteRole == role.obj.slice(0,2))
            //     return canAccess
            // } else {
            //     return userPermission.some(x => x.obj.includes(actionveRouteRole))
            // }
    }
}
