// import { CatalogRolesComponent } from '@/shared/catalog/roles';
import { CONSUMER_COMPONENTS_CONST } from '@/domains/consumer/constants';
import { AbstractFormDialog } from '@/shared/abstractClasses';
import { InputComponent } from '@/shared/components';
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
import { Component, inject, Input } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { IPosRequest, IPosResponse } from '../models';
import { ConsumerPosesService } from '../services/main.service';
import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component';

@Component({
  selector: 'consumer-pos-form',
  templateUrl: './form.component.html',
  imports: [ReactiveFormsModule, SharedDialogComponent, InputComponent, FormFooterActionsComponent],
})
export class ConsumerPosFormComponent extends AbstractFormDialog<IPosRequest, IPosResponse> {
  private readonly service = inject(ConsumerPosesService);

  @Input({ required: true }) posId!: string;

  initForm() {
    return CONSUMER_COMPONENTS_CONST.pos.initForm(this.fb, this.initialValues);
  }

  form = this.initForm();

  get preparedTitle() {
    return `ویرایش پایانه فروش ${this.initialValues?.name}`;
  }

  override ngOnChanges(): void {
    this.form = this.initForm();
  }

  submitForm() {
    const formValue = this.form.value as IPosRequest;
    return this.service.update(this.posId, formValue);
  }
}
