import {Component, EventEmitter, Input, Output} from '@angular/core';
import {Dialog} from 'primeng/dialog';
import {PostFormComponent} from '../../post-form/post-form.component';
import {Post} from '../../../models/post';
import {AuthService} from '../../../auth.service';
import {Author} from '../../../models/author';

@Component({
  selector: 'app-update-modal',
  standalone: true,
  imports: [
    Dialog,
    PostFormComponent
  ],
  templateUrl: './update-modal.component.html',
  styleUrl: './update-modal.component.css'
})
export class UpdateModalComponent {
  actualAuthor: Author | undefined;
  opened: boolean = true;
  @Input({required: true}) post: Post | undefined;
  @Output() updatedPost: EventEmitter<Post> = new EventEmitter<Post>();

  constructor(private authService: AuthService) {
    this.authService.getAuthenticatedAuthor();
  }


  onSubmit(updatedPost: Post) {
    this.updatedPost.emit(updatedPost);
    this.opened = false
  }
}
