import { CommonModule } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { IonButton, IonCard, IonContent, NavController } from '@ionic/angular/standalone';
import { CustomHeaderComponent } from 'src/lib/component/custom-header/custom-header.component';
import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';

@Component({
  selector: 'app-my-style-list',
  templateUrl: './my-style-list.component.html',
  styleUrls: ['./my-style-list.component.scss'],
  standalone: true,
  imports: [CustomHeaderComponent, IonContent, IonCard, IonButton, CommonModule]
})
export class MyStyleListComponent implements OnInit {
  constructor(private navCtrl: NavController) { }
  ngOnInit() {
    this.getStyleList();
  }
  /**
   * @页面跳转函数
   */
  goCreateStyle() {
    this.navCtrl.navigateForward('/generateOption', { state: { fromMyStyleListPage: true } });
  }
  goStyleDetail(style: CloudObject) {
    this.navCtrl.navigateForward('/generateOption', { state: { fromMyStyleInfoPage: true, style } });
  }
  /**
   * @读取风格列表
   */
  styleList: CloudObject[] = [];
  async getStyleList() {
    let query = new CloudQuery("UserStyleInfo");
    const user = new CloudUser().toPointer();
    query.equalTo("UserID", user);
    let result = await query.find();
    result = result.reverse();
    this.styleList = result;
    console.log(this.styleList);
  }
  /**
   * @内置功能函数
   */
  /*转换时间；格式例：2024-01-01 02:08*/
  convertTime(time: string): string {
    let date = new Date(time);
    return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`;
  }
}
