import { Component, OnInit } from '@angular/core';
import { StaticObjectController } from '@objects-view/static-object-controller';
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';
import { PoolCreateFormComponent } from '../tabs/pool-create-form/pool-create-form.component';
import { FleioId } from '@fleio-api/base-model/base-fleio-object.model';

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

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

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

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

  ngOnInit(): void {
  }
}
