import {
  ChangeDetectionStrategy,
  Component,
  isSignal,
  linkedSignal,
  Signal,
} from '@angular/core';
import { DialogContentDirective, NumberInputValidation } from '@isa/ui/dialog';
import { TextButtonComponent } from '@isa/ui/buttons';
import { provideIcons } from '@ng-icons/core';
import { isaActionSearch } from '@isa/icons';
import { SearchItemToRemitListComponent } from './search-item-to-remit-list.component';
import { ReturnItem } from '@isa/remission/data-access';

export type SearchItemToRemitDialogData = {
  searchTerm: string | Signal<string>;
};

// #5273, #4768 Fix - Nur ReturnItems sind zugelassen und dürfen zur Pflichtremission hinzugefügt werden
export type SearchItemToRemitDialogResult = ReturnItem;

@Component({
  selector: 'remi-search-item-to-remit-dialog',
  templateUrl: './search-item-to-remit-dialog.component.html',
  styleUrls: ['./search-item-to-remit-dialog.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
  standalone: true,
  imports: [TextButtonComponent, SearchItemToRemitListComponent],
  providers: [provideIcons({ isaActionSearch })],
})
export class SearchItemToRemitDialogComponent extends DialogContentDirective<
  SearchItemToRemitDialogData,
  Array<SearchItemToRemitDialogResult> | undefined
> {
  searchTerm = linkedSignal(() =>
    isSignal(this.data.searchTerm)
      ? this.data.searchTerm()
      : this.data.searchTerm,
  );
}
