import { Component, OnInit } from '@angular/core';
import {WeixinDefineDetailComponent} from '../weixin-define-detail/weixin-define-detail.component';
import {CookieService} from 'ngx-cookie-service';
import { FramePageComponent } from '../../../frame/core/page/frame.page';
import { BsModalService } from 'ngx-bootstrap/modal';
import { FuncService } from '../../../../core/service/func.service';

@Component({
  selector: 'app-weixin-define-page',
  templateUrl: './weixin-define-page.component.html',
  styleUrls: ['./weixin-define-page.component.scss']
})
export class WeixinDefinePageComponent extends FramePageComponent implements OnInit {

  currentWxId: any;
  constructor(private modalService: BsModalService, private cookies: CookieService) {
    super(modalService);
    if (this.cookies.get('CurrentWxId').length > 0) {
      this.currentWxId = parseInt(this.cookies.get('CurrentWxId'), 10) ;
    }
    this.modalComponent = WeixinDefineDetailComponent;
  }

  ngOnInit() {
  }


  checkTokenTime(v) {
    if (v.app_token_expired === undefined)
      return ''; 
    if (FuncService.shortStringToDate(v.app_token_expired) > new Date()) {
      return 'text-success';
    }
    return 'text-danger';
  }

  chooseWeixin(v) {
    this.currentWxId = v.wx_id;
    this.cookies.set('CurrentWxId', v.wx_id);
  }
}
