import { Component, Inject, OnInit } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { ConfigService } from '@shared/config/config.service';
import { IBaseDialog } from '@shared/common-dialogs/base-dialog';
import { IAction } from '@objects-view/interfaces/actions/action';
import { DialogCallbackAction } from '@objects-view/actions/dialog-callback-action';
import { AuthService } from '@shared/auth/auth.service';

@Component({
  selector: 'app-metric-detail-dialog',
  templateUrl: './metric-detail-dialog.component.html',
  styleUrls: ['./metric-detail-dialog.component.scss']
})
export class MetricDetailDialogComponent implements IBaseDialog, OnInit {
  dialogTitle = $localize`Metric details`;
  dialogActions: Array<IAction> = [
    new DialogCallbackAction({
      name: $localize`Close`,
      primary: true,
      callback: () => this.dialogRef.close(false),
    }),
  ];

  constructor(
    public config: ConfigService,
    public auth: AuthService,
    public dialogRef: MatDialogRef<MetricDetailDialogComponent>,
    @Inject(MAT_DIALOG_DATA) public data: {
      detailData: any[];
      currency: string;
    },
  ) { }

  ngOnInit(): void {
  }

  getEntryTooltip(item) {
    let text = $localize`Units: ${item.price_details.units}, Unit price: ${item.price_details.unit_price}`;
    if (item.price_details && item.price_details.time_unit) {
      text += $localize`, Time unit: ${item.price_details.time_unit}`;
    }
    return text;
  }
}
