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 { 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 { MembersCreateFormComponent } from '../tabs/members-create-form/members-create-form.component';

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

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

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

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

  ngOnInit(): void {
  }
}
