import { Component, OnInit } from '@angular/core';
import { ILBListenerModel } from '@fleio-api/openstack/load-balancing/model/lb-listener.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 { ListenerEditFormComponent } from '../tabs/listener-edit-form/listener-edit-form.component';
import { CallbackAction } from '@objects-view/actions/callback-action';
import { FleioId } from '@fleio-api/base-model/base-fleio-object.model';

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

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

  objectController = new StaticObjectController(
    {
      header: {
        title: {
          text: this.listener?.name || $localize`n/a`,
          subText: this.listener?.provisioning_status,
        }
      },
      tabs: [
        {
          tabName: $localize`Edit`,
          tabIdentifier: 'edit',
          component: ListenerEditFormComponent,
        },
      ],
      detailsActions: [
        new RouterLinkAction({
            name: $localize`Cancel`,
            routerUrl: this.config.getPanelUrl(
              `openstack/load-balancers/`,
              this.loadBalancerId,
            ),
            router: this.router,
            fragment: 'listeners',
            propagateQueryParams: ['region'],
          }
        ),
        new CallbackAction({name: $localize`Save`, propagateQueryParams: ['region'],}),
      ]
    },
    this.listener,
    {
      pools: this.activatedRoute.snapshot.data.pools,
    }
  );

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

  ngOnInit(): void {
  }
}
