import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class DataService {

  publishedItems: any[] = [
    { id: 1, 
      category: '求助', 
      route: '/tab11', 
      title: '求助！高数', 
      publisher: '小田' ,
      headImage:'/assets/images/start.png',
      timestamp:new Date('2022-05-06T10:30:00'),
      content: '期末快到了，求大神救救！求重点！',
      replies: [
      { floor:1, content: '求考试范围（哭）', sender: '燕燕' },
      { floor:2, content: '1楼+1', sender: '小万' },
    ]},
  ]
  tradeItems: any[] = [
    { id: 1, 
      category: '二手交易', 
      route: '/tab12', 
      title: 'ipad9二手出售',
      publisher: '燕燕' , 
      headImage:'/assets/images/play.png',
      timestamp:new Date('2022-03-16'),
      product: 'ipad9', 
      amount: '1000', 
      location: '枫林园宿舍1栋门口',
      image: '/assets/images/ipad9.jpg',
      remark: '九成新,心诚者可聊。',
      replies: [
      { floor:1, content: '价格还有少吗？', sender: '李小珊' },
    ]},
  ];
  lostFoundItems: any[] = [
    { id: 1, 
      category: '失物招领', 
      route: '/tab13', 
      title: '李小珊学生证', 
      publisher: '小万' ,
      headImage:'/assets/images/rgb.png',
      timestamp:new Date('2022-08-06T09:31:25'),
      item: '学生证', 
      status: '拾取', 
      location: '枫林园物华楼大厅', 
      time: '2024-07-01', 
      image: '/assets/images/学生证.jpg', 
      remark: '请认识李小珊的同学尽快联系我',
      replies: []},
  ];
  activityItems: any[] = [
    { id: 1, 
      category: '活动', 
      route: '/tab14', 
      title: '英语六级讲座', 
      publisher: '耶耶' ,
      headImage:'/assets/images/black.png',
      timestamp:new Date('2022-03-01T22:13:21'),
      name: '英语六级讲座', 
      target: '所有人', 
      startTime: '2024-07-10 15:00', 
      duration: '2 hours', 
      location: '青云楼报告厅', 
      remark: '有意愿的同学请准时参加' ,
      replies: []},
  ];

  constructor() { }

  //求助
  addReply(itemId: number, reply: any) {
    const item = this.publishedItems.find(item => item.id === itemId);
    if (item) {
      reply.floor = item.replies.length + 1;
      item.replies.push(reply);
    }
  }
  getPublishedItems() {
    return this.publishedItems;
  }

  //二手交易
  addReplyToTrade(itemId: number, reply: any) {
    const item = this.tradeItems.find(item => item.id === itemId);
    if (item) {
      reply.floor = item.replies.length + 1;
      item.replies.push(reply);
    }
  }
  getTradeItems() {
    return this.tradeItems;
  }

  //失物招领
  addReplyToLostFoundItems(itemId: number, reply: any) {
    const item = this.lostFoundItems.find(item => item.id === itemId);
    if (item) {
      reply.floor = item.replies.length + 1;
      item.replies.push(reply);
    }
  }
  getLostFoundItems() {
    return this.lostFoundItems;
  }

  //活动
  addReplyActivityItems(itemId: number, reply: any) {
    const item = this.activityItems.find(item => item.id === itemId);
    if (item) {
      reply.floor = item.replies.length + 1;
      item.replies.push(reply);
    }
  }
  getActivityItems() {
    return this.activityItems;
  }
}
