import { CommonModule } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { IonAvatar, IonCard, IonContent, IonImg, IonLabel } from '@ionic/angular/standalone';
import { constructOutline } from 'ionicons/icons';
import { CustomHeaderComponent } from 'src/lib/component/custom-header/custom-header.component';
import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';

@Component({
  selector: 'app-generate-history',
  templateUrl: './generate-history.component.html',
  styleUrls: ['./generate-history.component.scss'],
  standalone: true,
  imports: [CustomHeaderComponent, IonContent, IonCard, IonAvatar, IonLabel, CommonModule]
})
export class GenerateHistoryComponent implements OnInit {
  currentUser: CloudUser | any;
  history: CloudObject[] = [];
  constructor(private router: Router) {
    this.currentUser = new CloudUser();
  }
  ngOnInit() {
    this.getAllHistory();
  }
  async getAllHistory() {
    let query = new CloudQuery("GenerateResult");
    query.equalTo("UserID", this.currentUser.toPointer());
    let result = await query.find();
    this.history = result;
    console.log(this.history);
    this.history = this.history.reverse();
  }
  timeFormat(time: string) {
    //参考输入格式"2024-12-27T18:45:01.237Z"转化为中国区时间格式
    //输出格式"XXXX-XX-XX XX:XX"
    let date = new Date(time);
    //确保时间输出都是两位
    let year = date.getFullYear().toString().padStart(4, "0");
    let month = (date.getMonth() + 1).toString().padStart(2, "0");
    let day = date.getDate().toString().padStart(2, "0");
    let hour = date.getHours().toString().padStart(2, "0");
    let minute = date.getMinutes().toString().padStart(2, "0");
    return `${year}-${month}-${day} ${hour}:${minute}`;
  }
  goGenerateResult(obj: CloudObject | any) {
    this.router.navigate(['generateResult', obj.id]);
  }
}
