import { Component, OnInit } from '@angular/core';
import { FleioId } from '@fleio-api/base-model/base-fleio-object.model';
import { StaticObjectController } from '@objects-view/static-object-controller';
import { RouterLinkAction } from '@objects-view/actions/router-link-action';
import { ConfigService } from '@shared/config/config.service';
import { ActivatedRoute, Router } from '@angular/router';
import { ILBPoolModel } from '@fleio-api/openstack/load-balancing/model/lb-pool.model';
import { PoolDetailsOverviewComponent } from '../tabs/pool-details-overview/pool-details-overview.component';
import { PoolDetailsHealthmonitorsComponent } from '../tabs/pool-details-healthmonitors/pool-details-healthmonitors.component';
import { PoolDetailsMembersComponent } from '../tabs/pool-details-members/pool-details-members.component';
import { PoolsUtils } from '../pools-utils';
import { LBPoolsApiService } from '@fleio-api/openstack/load-balancing/pools/lb-pools-api.service';

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

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

  objectController = new StaticObjectController(
    {
      header: {
        title: {
          text: this.pool?.name || $localize`n/a`,
          subText: this.pool?.provisioning_status,
        }
      },
      tabs: [
        {
          tabName: $localize`Overview`,
          tabIdentifier: 'overview',
          component: PoolDetailsOverviewComponent,
        },
        {
          tabName: $localize`Health monitors`,
          tabIdentifier: 'health-monitors',
          component: PoolDetailsHealthmonitorsComponent,
        },
        {
          tabName: $localize`Members`,
          tabIdentifier: 'members',
          component: PoolDetailsMembersComponent,
        },
      ],
      actions: this.pool ? PoolsUtils.getPoolActions(
        this.pool, this.lbPoolsApiService, this.config, this.router, this.loadBalancerId,
      ) : [],
    },
    this.pool,
  );

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

  ngOnInit(): void {
  }
}
