import {Directive, ElementRef, Input, OnInit, Renderer2} from "@angular/core";
import {FrameService} from "../../../../core/service/frame.service";

@Directive({
  selector: '[frameRole]'
})
/************************
 * 权限判断，用于是否显示按钮
 */
export class FrameRoleDirective implements OnInit {


  @Input() resId;
  @Input() resAlias;
  @Input() optrType = 'display';

  constructor(private renderer: Renderer2, public element: ElementRef) {
  }

  ngOnInit(): void {
    if (!this.resId && !this.resAlias)
      this.resId = 0;
    const flag = FrameService.validateRole(this.resId);

    if (this.optrType === 'display') {
      this.element.nativeElement.style.display = (flag ? '' : 'none');
    } else {
      this.element.nativeElement.readonly = 'readonly';
    }

  }
}
