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 { 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 { ILBMemberModel } from '@fleio-api/openstack/load-balancing/model/lb-member.model';
import { MemberDetailsOverviewComponent } from '../tabs/member-details-overview/member-details-overview.component';
import { LBMembersApiService } from '@fleio-api/openstack/load-balancing/members/lb-members-api.service';

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

  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.member?.name || $localize`(none)`,
          subText: this.member?.provisioning_status,
        }
      },
      tabs: [
        {
          tabName: $localize`Overview`,
          tabIdentifier: 'overview',
          component: MemberDetailsOverviewComponent,
        },
      ],
      actions: this.member ? PoolsUtils.getMemberActions(
        this.member, this.lbMembersApiService, this.config, this.router, this.loadBalancerId, this.poolId,
      ) : [],
    },
    this.member,
  );

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

  ngOnInit(): void {
  }
}
