import { AbstractDialog } from '@/shared/abstractClasses/abstract-dialog';
import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component';
import { CustomerType } from '@/shared/localEnum/constants/customerTypes';
import { Component, EventEmitter, inject, Output, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { SelectButton } from 'primeng/selectbutton';
import { PosLandingStore } from '../../store/main.store';
import { CustomerIndividualFormComponent } from './individual/form.component';
import { CustomerLegalFormComponent } from './legal/form.component';
import { CustomerUnknownFormComponent } from './unknown/form.component';

@Component({
  selector: 'pos-order-customer-dialog',
  templateUrl: './customer-dialog.component.html',
  imports: [
    SharedDialogComponent,
    CustomerIndividualFormComponent,
    FormsModule,
    CustomerLegalFormComponent,
    SelectButton,
    CustomerUnknownFormComponent,
  ],
})
export class PosOrderCustomerDialogComponent extends AbstractDialog {
  @Output() onSubmit = new EventEmitter<any>();

  private readonly store = inject(PosLandingStore);

  customerTypes = [
    {
      label: 'نوع دوم',
      value: 'UNKNOWN',
    },
    {
      label: 'حقیقی (نوع اول)',
      value: 'INDIVIDUAL',
    },
    {
      label: 'حقوقی (نوع اول)',
      value: 'LEGAL',
    },
  ] as {
    label: string;
    value: CustomerType;
  }[];

  selectedCustomerType = signal<CustomerType>(this.store.customer().type);

  onSubmitCustomer() {
    this.close();
    this.onSubmit.emit();
  }
}
