import {Component, OnInit} from '@angular/core';
import {FrameDetailComponent} from "../../core/detail/frame.detail";
import {FormBuilder, Validators} from "@angular/forms";
import {FrameService} from "../../../../core/service/frame.service";
import {BsModalRef} from "ngx-bootstrap/modal";

@Component({
  selector: 'app-frame-role-detail',
  templateUrl: './frame-role-detail.component.html',
  styleUrls: ['./frame-role-detail.component.scss']
})
export class FrameRoleDetailComponent extends FrameDetailComponent implements OnInit {

  resArray: any;

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
    this.detailForm = fb.group({
      'role_name': [null, Validators.compose([Validators.required, Validators.minLength(2), Validators.maxLength(32)])],
      'role_status': [null, Validators.required],
      'role_type': [null],
      'home_page': [null],
      'thread_max': [null, Validators.compose([Validators.min(0), Validators.max(999)])],
      'role_desc': [null]
    });
  }

  ngOnInit() {
    const array = [];
    for (const res of FrameService.ResArray) {
      if (res.res_url) {
        array.push(res);
      }
    }
    this.resArray = array;
    setTimeout(() => {
      if (this.detailMode === 'add') {
        this.currentEntity.thread_max = FrameService.FrameOptr.thread_max;
      }
    });
  }
}
