import { Component, OnInit } from '@angular/core';
import { DetailsComponentBase } from '@objects-view/details-component-base';
import { ConfigService } from '@shared/config/config.service';
import { IObjectModel } from '@fleio-api/openstack/object-store/model/object.model';
import { ObjectsApiService } from '@fleio-api/openstack/object-store/objects/objects-api.service';
import { IContainerModel } from '@fleio-api/openstack/object-store/model/container.model';
import { FormatHelper } from '@shared/ui-api/helpers/format-helper';
import { ActivatedRoute } from '@angular/router';

@Component({
  selector: 'app-object-details-overview',
  templateUrl: './object-details-overview.component.html',
  styleUrls: ['./object-details-overview.component.scss'],
  providers: [ObjectsApiService],
})
export class ObjectDetailsOverviewComponent extends DetailsComponentBase<IObjectModel> implements OnInit {
  private container: IContainerModel;
  contentType = $localize`loading ...`;
  formatHelper = new FormatHelper();

  constructor(
    public config: ConfigService,
    private objectsApi: ObjectsApiService,
    private activatedRoute: ActivatedRoute,
  ) {
    super();
  }

  ngOnInit() {
    super.ngOnInit();
    if (this.objectController) {
      this.container = this.objectController.additionalObjects.container;
      const additionalQueryParams = Object.assign(
        {}, {container: this.container.id}, this.activatedRoute.snapshot.queryParams,
      );
      this.objectsApi.setAdditionalQueryParams(additionalQueryParams);
      this.objectsApi.metadata(this.object.id).subscribe(metadata => {
        this.contentType = metadata['content-type'];
      });
    }
  }
}
