import { Component, EventEmitter, Input, Output, ChangeDetectionStrategy } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { UserInfo, PatientProfile, PatientUpdateRequest } from '../../../../services/user.service';
import { UserService } from '../../../../services/user.service';

@Component({
  selector: 'app-patient-profile-panel',
  standalone: true,
  imports: [CommonModule, FormsModule],
  templateUrl: './patient-profile-panel.component.html',
  styleUrls: ['./patient-profile-panel.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class PatientProfilePanelComponent {
  @Input() currentUser: UserInfo | null = null;
  @Input() patientInfo: any = null;
  @Input() patientProfile: PatientProfile | null = null;
  @Input() showEditProfile = false;
  @Input() editUserData: { firstName: string; lastName: string; phoneNumber: string } = {
    firstName: '',
    lastName: '',
    phoneNumber: ''
  };
  @Input() editProfileData: PatientUpdateRequest | null = null;
  @Input() newAllergy = '';
  @Input() newMedication = '';

  @Output() editProfile = new EventEmitter<void>();
  @Output() cancelEdit = new EventEmitter<void>();
  @Output() saveProfile = new EventEmitter<void>();
  @Output() addAllergy = new EventEmitter<void>();
  @Output() removeAllergy = new EventEmitter<number>();
  @Output() addMedication = new EventEmitter<void>();
  @Output() removeMedication = new EventEmitter<number>();
  @Output() avatarSelected = new EventEmitter<Event>();
  @Output() newAllergyChange = new EventEmitter<string>();
  @Output() newMedicationChange = new EventEmitter<string>();

  constructor(public userService: UserService) {}

  onAvatarChange(event: Event): void {
    this.avatarSelected.emit(event);
  }

  onStartEdit(): void {
    this.editProfile.emit();
  }

  onCancelEdit(): void {
    this.cancelEdit.emit();
  }

  onSaveProfile(): void {
    this.saveProfile.emit();
  }

  onAddAllergy(): void {
    this.addAllergy.emit();
  }

  onRemoveAllergy(index: number): void {
    this.removeAllergy.emit(index);
  }

  onAddMedication(): void {
    this.addMedication.emit();
  }

  onRemoveMedication(index: number): void {
    this.removeMedication.emit(index);
  }
}

