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

@Component({
  selector: 'app-healthmonitor-create',
  templateUrl: './healthmonitor-create.component.html',
  styleUrls: ['./healthmonitor-create.component.scss']
})
export class HealthmonitorCreateComponent 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 health monitor`
        }
      },
      tabs: [
        {
          tabName: $localize`Edit`,
          tabIdentifier: 'edit',
          component: HealthmonitorEditFormComponent,
        },
      ],
      actions: [],
      detailsActions: [
        new RouterLinkAction({
            name: $localize`Back`,
            routerUrl: this.config.getPanelUrl(
              `openstack/load-balancers/${this.loadBalancerId}/pools`,
              this.poolId,
            ),
            fragment: 'health-monitors',
            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 {
  }
}
