import {
  Component,
  effect,
  EventEmitter,
  Input,
  Output,
  signal,
} from '@angular/core';
import { MarkdownComponent } from '../markdown/markdown.component';
import { FormsModule } from '@angular/forms';
import { Post } from '../../shared/interfaces/post';

@Component({
  selector: 'app-post-editor',
  imports: [MarkdownComponent, FormsModule],
  standalone: true,
  templateUrl: './post-editor.component.html',
})
export class PostEditorComponent {
  @Input('post') data = signal<Post>({
    id: 0,
    title: '',
    tldr: '',
    content: '',
  });
  @Output('postChange') dataChange = new EventEmitter<Post>();

  set title(val: string) {
    this.data.update((d) => ({ ...d, title: val }));
  }

  set tldr(val: string) {
    this.data.update((d) => ({ ...d, tldr: val }));
  }

  set content(val: string) {
    this.data.update((d) => ({ ...d, content: val }));
  }
}
