import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-borrow',
  templateUrl: './borrow.page.html',
  styleUrls: ['./borrow.page.scss'],
})
export class BorrowPage implements OnInit {
  segment: string = 'current';
  currentCount: number = 0;
  historyCount: number = 0;
  currentBooks: any[] = [];
  historyBooks: any[] = [];
  constructor() {
    // 模拟数据
    this.currentBooks = [
      { title: 'Book A', author: 'Author A', selected: false },
      { title: 'Book B', author: 'Author B', selected: false }
    ];
    this.historyBooks = [
      { title: 'Book C', author: 'Author C' },
      { title: 'Book D', author: 'Author D' }
    ];

    this.currentCount = this.currentBooks.length;
    this.historyCount = this.historyBooks.length;
  }
  isAnyCardSelected(): boolean {
    return this.currentBooks.some((book) => book.selected);
  }
  
  public alertButtons = [{text:'确定',role:'ok',}];
  public alertInputs = [
    {
      type: 'number',
      placeholder: '请输入续借天数',
      min: 1,
      max: 30,
    },
  ];
  onAlertDismiss(event:any) {
    if (event.detail.role === 'ok') {
      // 取消复选框的选中状态
      this.currentBooks.forEach((book) => {
        book.selected = false;
      });
      // 将续借按钮设为灰色
      const renewButton = document.getElementById('present-alert');
      if (renewButton) {
        renewButton.setAttribute('disabled', 'true');
      }
    }
  }
  ngOnInit() {
  }
  selectCard(card: any) {
    card.selected = !card.selected;
  }
}
