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 { RouterLinkAction } from '@objects-view/actions/router-link-action';
import { ConfigService } from '@shared/config/config.service';
import { ActivatedRoute, Router } from '@angular/router';
import { RuleDetailsOverviewComponent } from '../tabs/rule-details-overview/rule-details-overview.component';
import { ILBRuleModel } from '@fleio-api/openstack/load-balancing/model/lb-rule.model';
import { LBRulesApiService } from '@fleio-api/openstack/load-balancing/rules/lb-rules-api.service';

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

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

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

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


  objectController = new StaticObjectController(
    {
      header: {
        title: {
          text: $localize`Rule details`,
          subText: this.rule?.provisioning_status,
        }
      },
      tabs: [
        {
          tabName: $localize`Overview`,
          tabIdentifier: 'overview',
          component: RuleDetailsOverviewComponent,
        },
      ],
      actions: this.rule ? ListenerUtils.getRuleActions(
        this.rule, this.lbRulesApiService, this.config, this.router, this.loadBalancerId, this.listenerId,
        this.policyId,
      ) : [],
    },
    this.rule,
  );

  constructor(
    public config: ConfigService,
    private router: Router,
    private activatedRoute: ActivatedRoute,
    private lbRulesApiService: LBRulesApiService,
  ) {
  }

  ngOnInit(): void {
    this.lbRulesApiService.setAdditionalQueryParams({policy_id: this.policyId});
  }
}
