import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { PageapiService } from '../../pageapi.service';

@Component({
  selector: 'ngx-mixed-form',
  templateUrl: './mixed-form.component.html',
  styleUrls: ['./mixed-form.component.scss']
})
export class MixedFormComponent implements OnInit {
 
  setData:any =[];
 
  @Output() childButtonEvent = new EventEmitter();

  inputFieldGroups: { qty: string, productSpec: string }[] = [{ qty: '0', productSpec: '' }]; // Array to hold input field groups
  constructor(public _api:PageapiService) { 

    this._api.orderDetails_observable$.subscribe((res) => {
      console.log('booked', res);

      if(res){
 this. setData =   res.data
 if( this. setData['ProductDetails.productName'] == "Mixed Gas"){


 this.inputFieldGroups[0].qty =  this. setData.qty
 this.inputFieldGroups[0].productSpec  =  this. setData.productSpec
//  this.inputFieldGroups.push({ qty:  this. setData.qty, productSpec:  this. setData.productSpec });
}
      }
  
    })
  }

  ngOnInit(): void {
  }
  addInputFieldGroup() {
    this.inputFieldGroups.push({ qty: '0', productSpec: '' }); // Add a new input field group to the array
    this.childButtonEvent.emit( this.inputFieldGroups);
  }

  removeInputFieldGroup(index: number) {
    console.log(  this.inputFieldGroups)
    this.inputFieldGroups.splice(index, 1); // Remove the input field group at the specified index
    this.childButtonEvent.emit( this.inputFieldGroups);
  }

  pass(){
    this.childButtonEvent.emit( this.inputFieldGroups);
  }

}
