import { Component, OnInit } from '@angular/core';
import { StaticObjectController } from '@objects-view/static-object-controller';
import { ConfigService } from '@shared/config/config.service';
import { ListenerDetailsOverviewComponent } from '../tabs/listener-details-overview/listener-details-overview.component';
import { ListenerDetailsPoolsComponent } from '../tabs/listener-details-pools/listener-details-pools.component';
import { ListenerDetailsL7PoliciesComponent } from '../tabs/listener-details-l7-policies/listener-details-l7-policies.component';
import { ActivatedRoute, Router } from '@angular/router';
import { ILBListenerModel } from '@fleio-api/openstack/load-balancing/model/lb-listener.model';
import { ListenerUtils } from '../listener-utils';
import { LBListenersApiService } from '@fleio-api/openstack/load-balancing/listeners/lb-listeners-api.service';
import { FleioId } from '@fleio-api/base-model/base-fleio-object.model';

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

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

  objectController = new StaticObjectController(
    {
      header: {
        title: {
          text: this.listener?.name || $localize`n/a`,
          subText: this.listener?.provisioning_status,
        }
      },
      tabs: [
        {
          tabName: $localize`Overview`,
          tabIdentifier: 'overview',
          component: ListenerDetailsOverviewComponent,
        },
        {
          tabName: $localize`Pools`,
          tabIdentifier: 'pools',
          component: ListenerDetailsPoolsComponent,
        },
        {
          tabName: $localize`L7 policies`,
          tabIdentifier: 'l7-policies',
          component: ListenerDetailsL7PoliciesComponent,
        },
      ],
      actions: this.listener ? ListenerUtils.getListenerActions(
        this.listener, this.lbListenersApiService, this.config, this.router, this.loadBalancerId,
      ) : [],
    },
    this.activatedRoute.snapshot.data.listener,
  );

  constructor(
    public config: ConfigService,
    private router: Router,
    private activatedRoute: ActivatedRoute,
    private lbListenersApiService: LBListenersApiService,
  ) {
  }

  ngOnInit(): void {
  }
}
