import { Component, OnInit } from '@angular/core';
import { DataService } from '../data.service';
import { Title } from '@angular/platform-browser';
import { Router } from '@angular/router';

@Component({
  selector: 'app-tab11',
  templateUrl: './tab11.page.html',
  styleUrls: ['./tab11.page.scss'],
})

export class Tab11Page implements OnInit {

  replyContent: string = '';
  publishedItems: any[] = [];

  constructor(private dataService: DataService,private titleService: Title,private router: Router) {}

  ngOnInit() {
    this.publishedItems = this.dataService.getPublishedItems();
    if (this.publishedItems.length > 0) {
      this.titleService.setTitle(this.publishedItems[0].title);
    }
  }

  submitReply(item: any) {
    if (this.replyContent.trim() !== '') {
      const reply = { content: this.replyContent, sender: '小序', floor: 1 }; // 可以根据实际情况设置回复人,初始化楼层号
      this.dataService.addReply(item.id, reply);
      this.replyContent = ''; // 清空回复框
    }
  }

}
