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 { ListenerUtils } from '../listener-utils';
import { ConfigService } from '@shared/config/config.service';
import { ActivatedRoute, Router } from '@angular/router';
import { ILBPolicyModel } from '@fleio-api/openstack/load-balancing/model/lb-policy.model';
import { PolicyDetailsOverviewComponent } from '../tabs/policy-details-overview/policy-details-overview.component';
import { PolicyDetailsRulesComponent } from '../tabs/policy-details-rules/policy-details-rules.component';
import { LBPoliciesApiService } from '@fleio-api/openstack/load-balancing/policies/lb-policies-api.service';

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

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

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

  objectController = new StaticObjectController(
    {
      header: {
        title: {
          text: this.policy?.name || $localize`n/a`,
          subText: this.policy?.provisioning_status,
        }
      },
      tabs: [
        {
          tabName: $localize`Overview`,
          tabIdentifier: 'overview',
          component: PolicyDetailsOverviewComponent,
        },
        {
          tabName: $localize`L7 Rules`,
          tabIdentifier: 'l7-rules',
          component: PolicyDetailsRulesComponent,
        },
      ],
      actions: this.policy ? ListenerUtils.getPolicyActions(
        this.policy, this.lbPoliciesApiService, this.config, this.router, this.loadBalancerId, this.listenerId,
      ) : [],
    },
    this.policy,
  );

  constructor(
    public config: ConfigService,
    private router: Router,
    private activatedRoute: ActivatedRoute,
    private lbPoliciesApiService: LBPoliciesApiService,
  ) {
  }

  ngOnInit(): void {
  }
}
