import { Component } from '@angular/core';
import { AlertController } from '@ionic/angular';
import { Router } from '@angular/router';
@Component({
  selector: 'app-tab2',
  templateUrl: 'tab2.page.html',
  styleUrls: ['tab2.page.scss']
})
export class Tab2Page {

  contacts = [
    { name: '小江', phone: '13767975832', email: '1969965415' },
    { name: '小明', phone: '123456789', email: 'xiaoming@example.com' },
    { name: '小红', phone: '987654321', email: 'xiaohong@example.com' }
    // 其他联系人数据
  ];
  searchText: string = '';

  constructor(private alertController: AlertController,private router: Router) {}

  filterContacts() {
    return this.contacts.filter(contact => contact.name.toLowerCase().includes(this.searchText.toLowerCase()));
  }

  
  openMessages() {
    // 在这里编写打开消息页面的逻辑
    console.log('打开消息页面');
  }

  //添加联系人
  async add(){
  const alert = await this.alertController.create({
    header: '添加新继承人',
    inputs: [
      {
        name: 'name',
        type: 'text',
        placeholder: '姓名'
      },
      {
        name: 'phone',
        type: 'tel',
        placeholder: '电话'
      },
      {
        name: 'email',
        type: 'email',
        placeholder: '邮箱'
      }
    ],
    buttons: [
      {
        text: '取消',
        role: 'cancel'
      },
      {
        text: '确定',
        handler: (data) => {
          const newContact = {
            name: data.name,
            phone: data.phone,
            email: data.email
          };
          this.contacts.push(newContact);
        }
      }
    ]
  });
  await alert.present();
}
//切换界面
goContact(){
  console.log(11)
  this.router.navigate(['/contact']);
}
}
