import { Component, OnInit, Optional } from '@angular/core';
import { ProductsApiService } from '@fleio-api/billing/products/product-api.service';
import { ActivatedRoute } from '@angular/router';
import { PanelLayoutComponent } from '@shared/layout/panel-layout/panel-layout.component';
import { FleioId } from '@fleio-api/base-model/base-fleio-object.model';

@Component({
  selector: 'app-select-domain',
  templateUrl: './select-domain.component.html',
  styleUrls: ['./select-domain.component.scss']
})
export class SelectDomainComponent implements OnInit {
  clientId: FleioId;
  productCode: string;
  productName: string;

  constructor(
    private activatedRoute: ActivatedRoute,
    private productsApiService: ProductsApiService,
    @Optional() public panelLayout?: PanelLayoutComponent,
  ) {
    this.clientId = this.activatedRoute.snapshot.params.client;
    this.productCode = this.activatedRoute.snapshot.params.code;
  }

  ngOnInit(): void {
    this.productsApiService.list({
      search: this.productCode,
    }).subscribe(value => {
      for (const product of value.objects) {
        if (product.code === this.productCode) {
          this.productName = product.name;
          break;
        }
      }
    });
  }

  select() {
  }

}
