import { Component, OnInit } from '@angular/core';
import { ILBHealthMonitorModel } from '@fleio-api/openstack/load-balancing/model/lb-health-monitor.model';
import { FleioId } from '@fleio-api/base-model/base-fleio-object.model';
import { StaticObjectController } from '@objects-view/static-object-controller';
import { HealthmonitorDetailsOverviewComponent } from '../tabs/healthmonitor-details-overview/healthmonitor-details-overview.component';
import { PoolsUtils } from '../pools-utils';
import { RouterLinkAction } from '@objects-view/actions/router-link-action';
import { ConfigService } from '@shared/config/config.service';
import { ActivatedRoute, Router } from '@angular/router';
import { LBPoolsApiService } from '@fleio-api/openstack/load-balancing/pools/lb-pools-api.service';
import { LBHealthMonitorsApiService } from '@fleio-api/openstack/load-balancing/health-monitors/lb-health-monitors-api.service';

@Component({
  selector: 'app-healthmonitor-details',
  templateUrl: './healthmonitor-details.component.html',
  styleUrls: ['./healthmonitor-details.component.scss']
})
export class HealthmonitorDetailsComponent implements OnInit {
  get monitor(): ILBHealthMonitorModel {
    return this.activatedRoute.snapshot.data.monitor;
  }

  get loadBalancerId(): FleioId {
    return this.activatedRoute.snapshot.params.loadBalancerId;
  }

  get poolId(): FleioId {
    return this.activatedRoute.snapshot.params.id;
  }

  objectController = new StaticObjectController(
    {
      header: {
        title: {
          text: this.monitor?.name || $localize`n/a`,
          subText: this.monitor?.provisioning_status,
        }
      },
      tabs: [
        {
          tabName: $localize`Overview`,
          tabIdentifier: 'overview',
          component: HealthmonitorDetailsOverviewComponent,
        },
      ],
      actions: this.monitor ? PoolsUtils.getMonitorActions(
        this.monitor, this.lbHealthMonitorsApiService, this.config, this.router, this.loadBalancerId, this.poolId,
      ) : [],
    },
    this.monitor,
  );

  constructor(
    public config: ConfigService,
    private router: Router,
    private activatedRoute: ActivatedRoute,
    private lbPoolsApiService: LBPoolsApiService,
    private lbHealthMonitorsApiService: LBHealthMonitorsApiService,
  ) {
  }

  ngOnInit(): void {
  }
}
