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 { PolicyEditFormComponent } from '../tabs/policy-edit-form/policy-edit-form.component';
import { RouterLinkAction } from '@objects-view/actions/router-link-action';
import { CallbackAction } from '@objects-view/actions/callback-action';
import { ConfigService } from '@shared/config/config.service';
import { ActivatedRoute, Router } from '@angular/router';

@Component({
  selector: 'app-policy-create',
  templateUrl: './policy-create.component.html',
  styleUrls: ['./policy-create.component.scss']
})
export class PolicyCreateComponent implements OnInit {
  get loadBalancerId(): FleioId {
    return this.activatedRoute.snapshot.params.loadBalancerId;
  }

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

  objectController = new StaticObjectController(
    {
      header: {
        title: {
          text: $localize`Create policy`,
        }
      },
      tabs: [
        {
          tabName: $localize`Create`,
          tabIdentifier: 'create',
          component: PolicyEditFormComponent,
        },
      ],
      detailsActions: [
        new RouterLinkAction({
            name: $localize`Back`,
            routerUrl: this.config.getPanelUrl(
              `openstack/load-balancers/${this.loadBalancerId}/listeners`,
              this.listenerId,
            ),
            fragment: 'l7-policies',
            router: this.router,
            propagateQueryParams: ['region'],
          }
        ),
        new CallbackAction({name: $localize`Create`, propagateQueryParams: ['region'],}),
      ]
    },
    null,
    {
      createOptions: this.activatedRoute.snapshot.data.createOptions,
      pools: this.activatedRoute.snapshot.data.pools,
    }
  );

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

  ngOnInit(): void {
  }
}
