import {
  Component,
  OnInit,
  Input,
  ViewEncapsulation,
  Output,
  EventEmitter
} from '@angular/core';
import { CardModel } from '../../models/card-model';
import { CallbackModel } from '../../models/callback-model';
import { GenericHelper } from '../../helpers/generic-helper';

@Component({
  selector: 'app-card',
  templateUrl: './card.component.html',
  styleUrls: ['./card.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class CardComponent implements OnInit {
  // @Input() wishListModel: WishListModel;
  @Input() cardModel: CardModel;
  @Output() methodToExecute: EventEmitter<CallbackModel> = new EventEmitter<
    CallbackModel
  >();

  constructor() {}
  CallReturnMethod(returnVal: CallbackModel) {
    // check method with params
    GenericHelper.CallReturnMethod<CardComponent>(returnVal, this);
  }

  RemoveBrowsed(cm: CallbackModel) {
    this.methodToExecute.emit(cm);
  }
  AddToWishList(cm: CallbackModel) {
    this.cardModel.addWishExpanded = false;
    this.methodToExecute.emit(cm);
  }

  RemoveFromWishlist(cm: CallbackModel) {
    this.methodToExecute.emit(cm);
  }

  SendEmail(cm: CallbackModel) {
    const email = cm.returnValue;
    console.log('Email sent to : ' + email);
  }

  ActionMethod(cm: CallbackModel) {
    this.methodToExecute.emit(cm);
  }

  RedirectionMethod(cm: CallbackModel) {
    this.methodToExecute.emit(cm);
  }
  toggleExpansion() {
    this.cardModel.addWishExpanded = !this.cardModel.addWishExpanded;
  }

  ngOnInit() {}
}
