import {formatDate} from '@angular/common';
import {Component, OnInit, ChangeDetectionStrategy} from '@angular/core';
import {Observable} from 'rxjs';
import {map} from 'rxjs/operators';
import {StudentPaymentConfirmService} from 'src/app/core/service/student-payment/student-payment-confirm.service';
import { createQueryStringFromObject } from 'src/app/shared/util/func';

@Component({
    selector: 'app-online-summary',
    templateUrl: './online-summary.container.html',
    styleUrls: ['./online-summary.container.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush
})
export class OnlineSummaryContainer implements OnInit {
    paymentList$ = new Observable();

    constructor(
        private studentPaymentConfirmSV: StudentPaymentConfirmService
    ) {
    }

    ngOnInit(): void {

    }

    search(data) {
        if(data.date != null){
            data.date = formatDate(data.date, 'yyyy-MM-dd', 'en-US');
        }
        console.log(data);
        const query = createQueryStringFromObject(data)
        if(query){
            return this.paymentList$ = this.studentPaymentConfirmSV.search(`?${query}`)
          }else{
            return this.paymentList$ = this.studentPaymentConfirmSV.getAll()
          }
    }


}
