import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { FormUtils } from 'src/app/lib/utils/form-utils';

@Component({
  selector: 'app-art-refuse-reason',
  template: `
<form nz-form *ngIf="form" nzLayout="vertical" [formGroup]="form" (ngSubmit)="onSubmit()" autocomplete="off" novalidate>

  <nz-form-item>
    <nz-form-control i18n-nzErrorTip nzErrorTip="请填写拒稿理由" nzHasFeedback>
      <textarea nz-input nzAutosize i18n-placeholder placeholder="拒稿理由" formControlName="reason" id="resson"></textarea>
    </nz-form-control>
  </nz-form-item>

  <div class="text-end">
    <button nz-button class="me-2" type="button" (click)="modalRef.close()" i18n>取消</button>
    <button nz-button nzType="primary" type="submit" i18n>确认</button>
  </div>

</form>

  `,
  styles: [`

  `
  ]
})
export class ArtRefuseReasonComponent implements OnInit {
  @Output() onSuccess =  new EventEmitter<any>();
  form: FormGroup;

  constructor(
    public modalRef: NzModalRef,
    private fb: FormBuilder,
  ) { }

  ngOnInit(): void {
    this.form = this.fb.group({
      reason: [null, Validators.required]
    });
  }

  onSubmit() {
    if (this.form.invalid) return FormUtils.markAsDirty(this.form);

    this.onSuccess.emit(this.form.controls['reason'].value);
  }

}
