import { Pipe, PipeTransform } from '@angular/core';
import {of} from 'rxjs';

@Pipe({
    name: 'cheakseatall'
})
export class CheakseatallPipe implements PipeTransform {

    transform(array: any): unknown {
        // if(!array) return false
        let isOK:any = false;
        let maxSeat = 0;
        let Totalseat = 0;
        const ArrayAllStartSeat = [];
        const ArrayAllEndSeat = [];
        for (let i = 0; i < array.length; i++) {
            maxSeat = array[i].no_of_seats
            if (array[i].testing_seat_subjects.length !== 0){
                    const ArraySeat = array[i].testing_seat_subjects;
                for (let j = 0; j < ArraySeat.length; j++) {
                    if (ArraySeat[j].start_seat_no !== null){
                        ArrayAllStartSeat.push(ArraySeat[j].start_seat_no)
                    }
                    if (ArraySeat[j].end_seat_no !== null){
                        ArrayAllEndSeat.push(ArraySeat[j].end_seat_no)
                    }
                }
            }
            if (typeof (ArrayAllEndSeat[ArrayAllEndSeat.length - 1]) === 'number' && typeof (ArrayAllStartSeat[0]) === 'number'){
                Totalseat = ArrayAllEndSeat[ArrayAllEndSeat.length - 1] - ArrayAllStartSeat[0] + 1;
            }
            if (maxSeat < Totalseat) {
                return    isOK = true
            }
        }
        return isOK
    }

}
