import { Component, OnInit, Input } from '@angular/core';
import { BoxOrder } from 'src/app/models/box-order.model';

@Component({
  selector: 'app-order',
  templateUrl: './order.component.html',
  styleUrls: ['./order.component.css']
})
export class OrderComponent implements OnInit {
  @Input() boxOrder:BoxOrder;
  @Input() detail:boolean = false;
  subscription_id: number;

  constructor() { }

  ngOnInit(): void {
    this.checkSubscription();
  }

  dateFormat(d:Date) {
    const date = new Date(d);
    const month = (date.getMonth()+1)<=9 ? '0'+(date.getMonth()+1) : (date.getMonth()+1);
    const day = date.getDate()<=9 ? '0'+date.getDate() : date.getDate()
    return day + '/' + month + '/' + date.getFullYear();
  }

  checkSubscription() {
    this.boxOrder.lines.forEach( l => {
      if (l.user_subscription_id) this.subscription_id = l.user_subscription_id;
    })
  }

}
