import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { 
  IonHeader, IonToolbar, IonTitle, IonContent, 
  IonButton, IonButtons, IonIcon, IonCard, IonCardHeader, IonCardTitle, IonCardContent,
  IonItem, IonLabel, IonList, IonInput, IonTextarea, IonAvatar, IonSearchbar,
  ModalController,
  IonSegment,} from '@ionic/angular/standalone';
import { ExploreContainerComponent } from '../explore-container/explore-container.component';
import { CommonModule } from '@angular/common';
import { openPostPublisherModal } from 'src/lib/public/post-publisher/post-publisher.component';
import { CloudObject, CloudPost, CloudQuery, CloudUser } from 'src/lib/ncloud';
import { openUserLoginModal } from 'src/lib/user/modal-user-login/modal-user-login.component';

@Component({
  selector: 'app-tab1',
  templateUrl: 'tab1.page.html',
  styleUrls: ['tab1.page.scss'],
  standalone: true,
  imports: [
    CommonModule,
    IonHeader, IonToolbar, IonTitle, IonContent, ExploreContainerComponent,
 
    IonButton, IonButtons, IonIcon,IonSegment,

    IonCard, IonCardHeader, IonCardTitle, IonCardContent,
    IonList, IonItem, IonLabel, IonAvatar, IonInput, IonTextarea,IonSearchbar
  ],
  schemas: [CUSTOM_ELEMENTS_SCHEMA], 
})
export class Tab1Page {
  currentUser:CloudUser|undefined
  post:CloudPost|undefined


  constructor(private modalCtrl:ModalController){
    this.currentUser=new CloudUser();
    this.post=new CloudPost();
  }


    ngOnInit() {
      // 生命周期：页面加载后，运行帖子列表，加载函数
      this.loadFilmPostList()
    }
  
    // 创建用于数据列表存储的属性
    filmpostList:Array<CloudObject> = []

    // 查询并加载列表的函数
    async loadFilmPostList(){
      let query = new CloudQuery("FilmPost");
      this.filmpostList = await query.find()
    }

async openPublishModal(){

  if(!this.currentUser?.id){
    openUserLoginModal(this.modalCtrl);
  }
if(this.currentUser?.id){
  openPostPublisherModal(this.modalCtrl);
}

}

  likePost() {
   
  }

  commentPost() {
    // 评论逻辑
  }
  onSearch(event: any) {
        const searchTerm = event.target.value; // 获取用户输入的搜索内容
        console.log('搜索内容:', searchTerm);
        // 在这里添加搜索逻辑，例如过滤列表或导航到搜索结果页面
      }
  


  
}
