import { Component, EventEmitter, Output } from '@angular/core';

import { ReactiveFormsModule, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { LucideAngularModule, BookCopy, X } from 'lucide-angular';
import { TranslatePipe } from '@ngx-translate/core';

@Component({
    selector: 'app-lore-create',
    imports: [ReactiveFormsModule, LucideAngularModule, TranslatePipe],
    templateUrl: './lore-create.component.html',
    styleUrls: ['./lore-create.component.scss']
})
export class LoreCreateComponent {
  @Output() close = new EventEmitter<void>();
  @Output() created = new EventEmitter<{ name: string; description: string }>();

  readonly BookCopy = BookCopy;
  readonly X = X;

  form: FormGroup;

  constructor(private fb: FormBuilder) {
    this.form = this.fb.group({
      name: ['', Validators.required],
      description: ['']
    });
  }

  submit(): void {
    if (this.form.invalid) return;
    this.created.emit(this.form.value);
  }

  onCancel(): void {
    this.close.emit();
  }
}
