import { Component, effect, inject, signal } from '@angular/core';
import { PostEditorComponent } from '../../../components/post-editor/post-editor.component';
import { Post } from '../../../shared/interfaces/post';
import { PostsService } from '../../../shared/services/posts.service';
import { Location } from '@angular/common';

@Component({
  selector: 'app-create-post',
  imports: [PostEditorComponent],
  templateUrl: './create-post.component.html',
})
export class CreatePostComponent {
  private postsService = inject(PostsService);
  private location = inject(Location);
  post = signal<Post>({
    id: 0,
    title: '',
    tldr: '',
    content: '',
  });

  publish() {
    this.postsService.createPost(this.post());
    this.location.back();
  }
}
