import { Component, OnInit } from '@angular/core';
import {FormBuilder, Validators} from '@angular/forms';
import {FrameService} from '../../../../core/frame/frame.service';
import {BsModalRef} from 'ngx-bootstrap';
import {FrameEditComponent} from '../../core/FrameEditComponent';
import {DomSanitizer} from '@angular/platform-browser';

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

  resArray: any;
  constructor(bsModalRef: BsModalRef, fb: FormBuilder, san: DomSanitizer) {
    super(bsModalRef, san);
    this.valForm = 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.editModel === 'add') {
        this.currentEntity.thread_max = FrameService.FrameOptr.thread_max;
      }
    });
  }
}
