import { Component, input, OnInit, signal } from '@angular/core';
import { PaginatorModule } from 'primeng/paginator';
import { ReactiveFormsModule } from '@angular/forms';
import { UntilDestroy } from '@ngneat/until-destroy';
import { MyProfileUpdateProjectFormComponent } from '@app/shared/components/my-profile-update-project-form/my-profile-update-project-form.component';
import { ProjectFacade } from '@app/adapters/projects/project.facade';

@Component({
  selector: 'app-my-profile-project-list',
  standalone: true,
  imports: [PaginatorModule, ReactiveFormsModule, MyProfileUpdateProjectFormComponent],
  templateUrl: './my-profile-project-list.component.html',
  styleUrl: './my-profile-project-list.component.scss',
})
@UntilDestroy()
export class MyProfileProjectListComponent implements OnInit {
  projectIds = input.required<string[]>();
  userId = input<string>('');

  protected projectIdSelected = signal<string | null>(null);

  private readonly projectFacade = new ProjectFacade();
  protected projects = this.projectFacade.projects;

  ngOnInit(): void {
    this.projectFacade.load(this.userId());
  }

  onProjectFormSubmitted($event: string | null) {
    this.projectIdSelected.set(null);
  }
}
