import { AbstractDialog } from '@/shared/abstractClasses/abstract-dialog';
import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component';
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { Observable } from 'rxjs';
import { SharedGoodFormComponent } from './form.component';
import { IGoodResponse } from './types';

@Component({
  selector: 'shared-good-form-dialog',
  templateUrl: './form-dialog.component.html',
  imports: [SharedDialogComponent, SharedGoodFormComponent],
})
export class ConsumerUserFormDialogComponent extends AbstractDialog {
  @Output() onSubmit = new EventEmitter<IGoodResponse>();
  @Input() initialValues?: IGoodResponse;
  @Input() editMode?: boolean;
  @Input({ required: true }) guildId!: string;

  @Input() createFn?: (payload: FormData) => Observable<IGoodResponse>;
  @Input() updateFn?: (payload: FormData) => Observable<IGoodResponse>;

  get preparedTitle() {
    return `${this.editMode ? 'ویرایش' : 'افزودن'} کالا`;
  }

  onFormSubmit(response: IGoodResponse) {
    this.onSubmit.emit(response);
    this.close();
  }
}
