import { Component, OnInit } from '@angular/core';
import { FormGroup, Validators } from '@angular/forms';
import { validateEmail } from '../../../validators/email-validator';
import { organisationB2bDeliveryValidator } from '../../../validators/organisation-delivery-b2b-validator';
import { ShippingCreateComponent } from './shipping-create.component';

@Component({
  selector: 'page-shipping-create-b2b',
  templateUrl: 'shipping-create-b2b.component.html',
  styleUrls: ['../address.component.scss'],
})
export class ShippingCreateB2BComponent extends ShippingCreateComponent {
  initForm(): FormGroup {
    const fb = this.fb;

    return fb.group(
      {
        gender: fb.control(undefined, [Validators.required, Validators.min(1)]),
        title: fb.control(''),
        firstName: fb.control('', [Validators.required]),
        lastName: fb.control('', [Validators.required]),
        organisation: fb.group({
          name: fb.control(''),
          department: fb.control(''),
          vatId: fb.control(''),
        }),
        address: fb.group({
          street: fb.control('', [Validators.required]),
          streetNumber: fb.control('', [Validators.required]),
          zipCode: fb.control('', [Validators.required]),
          city: fb.control('', [Validators.required]),
          info: fb.control(''),
          country: fb.control('DEU', [Validators.required]),
        }),
        communicationDetails: fb.group({
          email: fb.control('', [validateEmail]),
          phone: fb.control(''),
          mobile: fb.control(''),
        }),
        isDefault: fb.control(false),
      },
      { validators: organisationB2bDeliveryValidator() }
    );
  }
}
