import { Component, OnInit, ViewChild } from '@angular/core';
import { Product } from 'src/app/core/services/product';
import * as FileSaver from 'file-saver';
import { MatMenuTrigger } from '@angular/material/menu';
import { API } from 'src/app/core/services/api.service';
import { MessageService } from 'primeng/api';
import { Router } from '@angular/router';
import { CommonService } from 'src/app/core/services/common.service';
import { GetActivitySlot } from 'src/app/core/models/Experience-Service/slot/add-slots-model';
import * as moment from 'moment';
import { StaticDataService } from 'src/app/core/common/static-data.service';
@Component({
  selector: 'slots',
  templateUrl: './slots.component.html',
})
export class SlotsComponent implements OnInit {
  @ViewChild('menuTrigger') menuTrigger: MatMenuTrigger;

  displayModal: boolean;
  AllSlots: any;

  showModalDialog() {
    this.displayModal = true;
  }
  constructor(public ApiServ: API, private MsgService: MessageService, public router: Router, public CommonVari: StaticDataService) { }
  StartTime;
  EndTime;
  ngOnInit(): void {
  }

  GetAllSlot() {
    let post = new GetActivitySlot();
    let activity_id = CommonService.getSessionStoage('activity_id');
    post.activity_id = activity_id;
    post.from_hour = this.StartTime ? this.StartTime.split(':')[0] : null;
    post.from_minute = this.StartTime ? this.StartTime.split(':')[1] : null;
    post.to_hour = this.EndTime ? this.EndTime.split(':')[0] : null;
    post.to_minute = this.EndTime ? this.EndTime.split(':')[1] : null;
    this.ApiServ.Post('/ActivitySlot/GetAllSlot', post).subscribe(res => {
      if (res) {
        this.AllSlots = res['responseObject'];
      }
    });
  }
  reset() {
    this.EndTime = null;
    this.StartTime = null
  }
  UpdateStatus(slot_id, status) {
    let obj = { Id: slot_id, Status: status ? false : true }
    this.ApiServ.Post('/ActivitySlot/UpdateStatus', obj).subscribe(data => {
      if (data) {
        this.GetAllSlot();
        this.MsgService.add({
          severity: data["status"] ? "success" : "error",
          detail: data["message"],
        });
      }
    })
  }

  // table
  cols!: any[];

  Edit(pk_id) {
    let obj = { id: pk_id };
    this.router.navigate(['/Services/ActivityServices/ExpServices/Manage/AddSlots'], { queryParams: obj });
  }
}
