import { Component, OnInit } from '@angular/core';
import { Location } from '@angular/common';
import { Router, ActivatedRoute } from '@angular/router';
import { MyordersService } from './../../config/myorder.service';

@Component({
  selector: 'app-myorder',
  templateUrl: './myorder.page.html',
  styleUrls: ['./myorder.page.scss'],
})
export class MyorderPage implements OnInit {

  constructor(
    private router: Router,
    private route: ActivatedRoute,
    private location: Location,
    public myorder: MyordersService
  ) { }

  ngOnInit() {
  }

  goToPage(path, data = null) {
    this.router.navigateByUrl(path, { queryParams: data });
    document.body.scrollTop = document.documentElement.scrollTop = 0;
  }

  goBack() {
    this.location.back();
  }

  orderDetails(index: number) {
      this.myorder.trackOrder(this.myorder.orders[index]);
      this.router.navigateByUrl('trackorder');
      document.body.scrollTop = document.documentElement.scrollTop = 0;
  }

  getStatus(status: number) {
    switch (status) {
      case 1:
        return 'Booked';
        break;
      case 2:
        return 'Shop Accepted';
        break;
      case 3:
        return 'Rider Assigned';
        break;
      case 4:
        return 'Reached Shop';
        break;
      case 5:
        return 'Picked Up';
        break;
      case 6:
        return 'Reached Location';
        break;
      case 7:
        return 'Delivered';
        break;
      case 8:
        return 'Rejected';
        break;
      default:
        return 'Finished';
    }
  }

}
