import { Component, Input, EventEmitter, Output } from '@angular/core';
import { RemissionProduct } from '@isa/remission';

@Component({
  selector: 'app-remission-list-card',
  templateUrl: './remission-list-card.component.html',
  styleUrls: ['./remission-list-card.component.scss'],
})
export class RemissionListCardComponent {
  @Input()
  get product(): RemissionProduct {
    return this._product;
  }
  set product(value: RemissionProduct) {
    this._product = value;
    this.toolTipOpened = new Array(value.features.length).fill(false);
  }
  @Input() last = false;

  @Output() deleteProduct = new EventEmitter<void>();

  selectedFeatureDescription: string;
  toolTipOpened = [];
  tooltipMl = -10;
  tooltipArrowMl = 5;
  private _product: RemissionProduct;
  constructor() {}

  openTooltip(index: number) {
    this.toolTipOpened = this.toolTipOpened.map((opened, i) => (opened = index === i ? true : false));
  }

  closeTooltip(index: number) {
    this.toolTipOpened[index] = false;
  }

  isArray(obj) {
    return Array.isArray(obj);
  }

  getObjectKey(obj, index) {
    return Object.keys(obj)[index];
  }

  getObjectValue(obj, index) {
    return obj[Object.keys(obj)[index]];
  }
}
