import { CommonModule } from '@angular/common';
import { Component, OnDestroy, OnInit, signal, ViewChild } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { Table, TableModule } from 'primeng/table';
import { Person } from '../models';
import { IconFieldModule } from 'primeng/iconfield';
import { InputIconModule } from 'primeng/inputicon';
import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog';
import { ButtonModule } from 'primeng/button';
import { InputTextModule } from 'primeng/inputtext';

@Component({
  selector: 'app-pickperson',
  imports: [TableModule, ButtonModule,CommonModule, InputTextModule, FormsModule,IconFieldModule,InputIconModule],
  templateUrl: './pickperson.html',
  styleUrl: './pickperson.css'
})
export class Pickperson implements OnInit, OnDestroy{
  @ViewChild(Table) dt2!: Table;
  constructor(public ref: DynamicDialogRef, public config: DynamicDialogConfig)
  {
    
  }
  loading = false;
  familyList = signal<Person[]>([]);
  selectedPerson!: Person;
  handleInput(event: Event) {
    const value = (event.target as HTMLInputElement).value;
    this.dt2.filterGlobal(value, 'contains');
  }

  edit(id: number): void {

  }
  cancel(e:Event):void {
    e.preventDefault();
    this.ref.close(null);
  }
  select(e:Event):void {
    e.preventDefault();
    this.ref.close(this.selectedPerson);
  }

  ngOnDestroy(): void {
    
  }
  ngOnInit(): void {
    console.log("pick person the familyList", this.config);
    this.familyList.set(this.config.data.familyList);
    
  }

}
