import { MustMatch, password } from '@/core/validators';
import { AbstractFormDialog } from '@/shared/abstractClasses';
import { SharedPasswordInputComponent } from '@/shared/components';
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
import { Component, inject, Input } from '@angular/core';
import { ReactiveFormsModule, Validators } from '@angular/forms';
import { IAccountRequest, IAccountResponse } from '../models';
import { AccountsService } from '../services/main.service';
import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component';

@Component({
  selector: 'account-password-form',
  templateUrl: './form.component.html',
  imports: [ReactiveFormsModule, SharedDialogComponent, FormFooterActionsComponent, SharedPasswordInputComponent],
})
export class PartnerAccountPasswordFormComponent extends AbstractFormDialog<
  IAccountRequest,
  IAccountResponse
> {
  @Input({ required: true }) accountId!: string;
  private service = inject(AccountsService);

  form = this.fb.group(
    {
      password: ['', [Validators.required, password()]],
      confirmPassword: ['', [Validators.required]],
    },
    {
      validators: [MustMatch('password', 'confirmPassword')],
    },
  );

  override submitForm(payload: IAccountRequest) {
    return this.service.update(this.accountId, payload);
    // @ts-ignore
    // const { confirmPassword, ...rest } = payload;
    // return this.service.create(rest);
  }
}
