import { Component, inject } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';

import SharedModule from 'app/shared/shared.module';
import { ITEM_DELETED_EVENT } from 'app/config/navigation.constants';
import { IMetadataProperty } from '../metadata-property.model';
import { MetadataPropertyService } from '../service/metadata-property.service';

@Component({
  standalone: true,
  templateUrl: './metadata-property-delete-dialog.component.html',
  imports: [SharedModule, FormsModule],
})
export class MetadataPropertyDeleteDialogComponent {
  metadataProperty?: IMetadataProperty;

  protected metadataPropertyService = inject(MetadataPropertyService);
  protected activeModal = inject(NgbActiveModal);

  cancel(): void {
    this.activeModal.dismiss();
  }

  confirmDelete(id: number): void {
    this.metadataPropertyService.delete(id).subscribe(() => {
      this.activeModal.close(ITEM_DELETED_EVENT);
    });
  }
}
