import { Component, Input, OnInit } from '@angular/core';
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { Subscription } from 'rxjs';
import { AuthorizedStatesService } from 'src/app/services/authorizedStates/authorized-states.service';

@Component({
  standalone: false,
  selector: 'app-delete-auth-state-license-modal',
  templateUrl: './delete-auth-state-license-modal.component.html',
  styleUrls: ['./delete-auth-state-license-modal.component.scss']
})
export class DeleteAuthStateLicenseModalComponent implements OnInit {

  @Input() deleteLicenseModalClose!: () => void;
  @Input() authstateId!: number;
  @Input() licenseAuthType!: string;
  @Input() DeleteAuthStateLicenseModal!:NgbModalRef;

  constructor(private authorizedStatesService : AuthorizedStatesService) { }

  ngOnInit(): void {
  }

  /**
  * remove Restricted Categories by state relation
  *
  */
  deleteStateLicenseSubscribe!: Subscription;
  deleteStateLicense(stateId: number, authType: string){
    var requestData = {
       "state_id": stateId,
       "auth_type": authType
    };
    this.deleteStateLicenseSubscribe = this.authorizedStatesService.removeStateLicense(requestData)
    .subscribe({
      next: () => {
        this.deleteLicenseModalClose();
      },
      error: (err) => {
        this.authorizedStatesService.errorCallBack(err);
      },
      complete: () => { },
    })
  };

}