// Angular Core
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';

// Interfaces
import { scheduleControlListInterface } from 'src/app/interfaces/common-interfaces';
import { SuppliersMainSettingsInterface } from 'src/app/interfaces/supplier/suppliers-main-settings-interface';

@Component({
  standalone: false,
  selector: 'app-supplier-schedule-products',
  templateUrl: './supplier-schedule-products.component.html',
  styleUrls: ['./supplier-schedule-products.component.scss']
})
export class SupplierScheduleProductsComponent implements OnInit {

  @Input() supplierData!:SuppliersMainSettingsInterface['data']['supplierData'];
  @Input() supplierControls!:scheduleControlListInterface['data'];
  @Input() show_scheduleName_err_msg!:boolean;
  @Input() validate_scheduleName_msg!:string;
  @Input() IsDisabled!:boolean;

  @Output() deleteRecord = new EventEmitter<number>();
  @Output() fetchSchedule = new EventEmitter<object>();

  constructor() { }

  ngOnInit(): void {
  }

  /**
   * Function to emit deleteRecord Data to listen that emitter into the  parent component
   * @param {number} ndc
   */
  calldeleteRecordFunc(ndc: number){
    this.deleteRecord.emit(ndc);
  }

  /**
   * Function to emit fetchSchedule event emitter to listen that into the parent component
   */
  calldfetchScheduleFunc(){
    this.fetchSchedule.emit({});
  }

  trackByFn(index: number, item:any): void {
    return item
  }
    onProductNameInput(event: any) {
        this.supplierData.productName = event.target.value;
        this.calldfetchScheduleFunc();
    }

    onScheduleNameChange(event: any) {
        this.supplierData.scheduleName = event.target.value;
    }
}
