import { Component, OnInit, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { Store } from '@ngxs/store';
import { ChangeCurrentRoute } from 'apps/sales/src/app/core/store/actions/process.actions';
import { AddBreadcrumb } from 'apps/sales/src/app/core/store/actions/breadcrumb.actions';
import { Router } from '@angular/router';

@Component({
  selector: 'app-confirmation-overview',
  templateUrl: './confirmation-overview.component.html',
  styleUrls: ['./confirmation-overview.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ConfirmationOverviewComponent implements OnInit {
  @Input() customerName: string;
  @Input() customerId: number;
  @Input() isPickUpOnly: boolean;
  @Input() isTakeNowOnly: boolean;
  @Input() isDelivery: boolean;
  @Input() isDownload: boolean;
  @Input() deliveryAddress: string;
  @Input() email: string;
  @Input() orderId: number;
  @Input() orderNumber: number;
  @Input() orderDate: string;
  @Input() orderBranch: string;
  @Input() orderBranchAddress: string;
  @Output() printOrder: EventEmitter<number> = new EventEmitter();

  constructor(private store: Store, private router: Router) {}

  ngOnInit() {}

  print() {
    this.printOrder.emit(this.orderId);
  }

  goToDetails() {
    const route = `/customer/${this.customerId}/order/${this.orderId}`;
    this.store.dispatch(new ChangeCurrentRoute(route));
    this.store.dispatch(
      new AddBreadcrumb(
        {
          name: 'Bestelldetails',
          path: route,
        },
        'checkout'
      )
    );
    this.router.navigate([route]);
  }
}
