import { Component, OnInit } from '@angular/core';
import { ILBHealthMonitorModel } from '@fleio-api/openstack/load-balancing/model/lb-health-monitor.model';
import { FleioId } from '@fleio-api/base-model/base-fleio-object.model';
import { StaticObjectController } from '@objects-view/static-object-controller';
import { PoolsUtils } from '../pools-utils';
import { RouterLinkAction } from '@objects-view/actions/router-link-action';
import { ConfigService } from '@shared/config/config.service';
import { ActivatedRoute, Router } from '@angular/router';
import { LBPoolsApiService } from '@fleio-api/openstack/load-balancing/pools/lb-pools-api.service';
import { LBHealthMonitorsApiService } from '@fleio-api/openstack/load-balancing/health-monitors/lb-health-monitors-api.service';
import { HealthmonitorEditFormComponent } from '../tabs/healthmonitor-edit-form/healthmonitor-edit-form.component';
import { CallbackAction } from '@objects-view/actions/callback-action';

@Component({
  selector: 'app-healthmonitor-edit',
  templateUrl: './healthmonitor-edit.component.html',
  styleUrls: ['./healthmonitor-edit.component.scss']
})
export class HealthmonitorEditComponent implements OnInit {
  get monitor(): ILBHealthMonitorModel {
    return this.activatedRoute.snapshot.data.monitor;
  }

  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`Edit health monitor${this.monitor?.name}`,
        }
      },
      tabs: [
        {
          tabName: $localize`Edit`,
          tabIdentifier: 'edit',
          component: HealthmonitorEditFormComponent,
        },
      ],
      actions: this.monitor ? PoolsUtils.getMonitorActions(
        this.monitor, this.lbHealthMonitorsApiService, this.config, this.router, this.loadBalancerId, this.poolId,
      ) : [],
      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`Save`, propagateQueryParams: ['region'],}),
      ]
    },
    this.monitor,
    {
      createOptions: this.activatedRoute.snapshot.data.createOptions,
    }
  );

  constructor(
    public config: ConfigService,
    private router: Router,
    private activatedRoute: ActivatedRoute,
    private lbPoolsApiService: LBPoolsApiService,
    private lbHealthMonitorsApiService: LBHealthMonitorsApiService,
  ) {
  }

  ngOnInit(): void {
  }
}
