import { AbstractFormDialog } from '@/shared/abstractClasses';
import { InputComponent } from '@/shared/components';
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
import { UikitFlatpickrJalaliComponent } from '@/uikit';
import { nowJalali } from '@/utils';
import { Component, inject, Input } from '@angular/core';
import { ReactiveFormsModule, Validators } from '@angular/forms';
import { IAdminPartnerChargeAccountRequest } from '../../models/chargeAccount_io';
import { AdminPartnerChargeAccountService } from '../../services/chargeAccount.service';
import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component';

@Component({
  selector: 'admin-partner-charge-account-form-dialog',
  templateUrl: './charge-account-form-dialog.component.html',
  imports: [
    SharedDialogComponent,
    ReactiveFormsModule,
    InputComponent,
    FormFooterActionsComponent,
    UikitFlatpickrJalaliComponent,
  ],
})
export class AdminPartnerChargeAccountFormDialogComponent extends AbstractFormDialog<
  IAdminPartnerChargeAccountRequest,
  any
> {
  @Input({ required: true }) partnerId!: string;

  private readonly service = inject(AdminPartnerChargeAccountService);

  form = this.fb.group({
    quantity: [0, [Validators.required, Validators.min(1)]],
    activated_expires_at: ['', [Validators.required]],
  });

  minDate = nowJalali();

  submitForm(payload: IAdminPartnerChargeAccountRequest) {
    return this.service.charge(this.partnerId, payload);
  }
}
